问题是这样的: 在asp.net中,把dataTable中的数据导入到excel. 目前本地已经测试没有问题,但局域网中的其它机子访问导出后的excel文件时,没有任何反映. 我已经设置了文件目录everyone读写权限. 以及在Dcom配置中的excel应用程序的"启动和激活权限" "访问权限" 给于了everyone所有的权限.Excel.ApplicationClass myApp;
Excel.Workbook myBook;
Excel.Worksheet mySheet;
string tableName = "mp_ZZFY";
string FilePath = Server.MapPath(tableName); //模板文件路径myApp = null;
myBook = null;
mySheet = null; object oMissiong = System.Reflection.Missing.Value; myApp = new Excel.ApplicationClass(); myApp.Visible = false; myApp.Workbooks.Open(FilePath, oMissiong,oMissiong,oMissiong,oMissiong,oMissiong,oMissiong,oMissiong,oMissiong,oMissiong,oMissiong,oMissiong,oMissiong,oMissiong,oMissiong); myBook=myApp.Workbooks[1]; mySheet=(Excel.Worksheet)myBook.ActiveSheet; #region 一个萝卜一个坑
mySheet.Cells[i,j] = DataTable中的数据;
.......
#endregion
myBook.Save();myBook.Close(true,FilePath,true); //myApp.Quit(); System.Runtime.InteropServices.Marshal.ReleaseComObject(mySheet); System.Runtime.InteropServices.Marshal.ReleaseComObject(myBook); System.Runtime.InteropServices.Marshal.ReleaseComObject(myApp); GC.Collect();
#endregionResponse.Redirect(FilePath);
Excel.Workbook myBook;
Excel.Worksheet mySheet;
string tableName = "mp_ZZFY";
string FilePath = Server.MapPath(tableName); //模板文件路径myApp = null;
myBook = null;
mySheet = null; object oMissiong = System.Reflection.Missing.Value; myApp = new Excel.ApplicationClass(); myApp.Visible = false; myApp.Workbooks.Open(FilePath, oMissiong,oMissiong,oMissiong,oMissiong,oMissiong,oMissiong,oMissiong,oMissiong,oMissiong,oMissiong,oMissiong,oMissiong,oMissiong,oMissiong); myBook=myApp.Workbooks[1]; mySheet=(Excel.Worksheet)myBook.ActiveSheet; #region 一个萝卜一个坑
mySheet.Cells[i,j] = DataTable中的数据;
.......
#endregion
myBook.Save();myBook.Close(true,FilePath,true); //myApp.Quit(); System.Runtime.InteropServices.Marshal.ReleaseComObject(mySheet); System.Runtime.InteropServices.Marshal.ReleaseComObject(myBook); System.Runtime.InteropServices.Marshal.ReleaseComObject(myApp); GC.Collect();
#endregionResponse.Redirect(FilePath);
解决方案 »
- 一个表名生成增删改查代码
- AJAX做了一个无刷新排序,在谷歌和火狐都可以成功,但IE9上不行,不知道为什么
- CDMA短信猫dll调用
- 关于中国移动短信发送的例子
- 如何在.cs中找到html控件并取出他的值呢 20分
- javascript 选中某一行(在线等,分不多,最后的分数)
- AJAX能用服务器端控件来显示数据吗????(比如gridview)
- asp.net三层架构中 如何使用aspnetpager+objectdatasource+datalist页?
- 成都的朋友,大家好有事请教,自己心里实在是没底,
- HttpModule和HttpHandler的请求验证
- LoginView的viewchanged事件
- |M| 200分求救:.NET Freamework2.0 SDK mscorcfg.msc 运行库安全策略的问题 谢谢
private void btnMIME_Click(object sender, System.EventArgs e)
{
BindData(); Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Content-Disposition", "inline;filename="
+ HttpUtility.UrlEncode("下载文件.xls",Encoding.UTF8 ) );
//如果输出为Word,修改为以下代码
//Response.ContentType = "application/ms-word"
//Response.AddHeader("Content-Disposition", "inline;filename=test.doc")
StringBuilder sb=new StringBuilder();
System.IO.StringWriter sw = new System.IO.StringWriter(sb);
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(sw);
sb.Append("<html><body>");
dgShow.RenderControl(hw);
sb.Append("</body></html>");
Response.Write(sb.ToString());
Response.End();
}
private DataSet BindData()
{
SqlConnection myConnection = new SqlConnection( "server=(local);uid=sa;pwd=111;database=Pubs" );
DataSet myDataSet = new DataSet();
SqlDataAdapter myDataAdapter = new SqlDataAdapter("Select * From Authors", myConnection );
myDataAdapter.Fill( myDataSet, "Authors" );
dgShow.DataSource = myDataSet.Tables[0].DefaultView;
dgShow.DataBind();
return myDataSet;
}