.NET 中Excel导出文件问题!1 文件名称或路径不存在2 文件正被其他程序使用。 3 您正要保存的工作簿与当前打开的工作簿同名。
在做导出Excel问题的时候,本地里面能够试验成功,但是发布到了服务器上文件就导出失败了,
错误提示是:
1 文件名称或路径不存在
2 文件正被其他程序使用
3 您正要保存的工作簿与当前打开的工作簿同名
尝试过各种办法
如在"DCOM配置"中找到"Microsoft Excel 应用程序",在它上面点击右键"等等此类解决方法,都不行。
在此希望朋友们给个建议,到底怎么改才能导出成功!
.NET
Excel
Excel导出失败
--------------------编程问答--------------------
调用这个把 骚年!
private void DataSetToExcel(string FileName,DataSet ds)
{
string style = "";//防止导出excel时将以0开头的全数字数据的0去掉
//GridView gridview = new GridView();
//gridview.DataSource = dst;
//gridview.DataBind();
DateTime now = System.DateTime.Now;
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Charset = "";
HttpContext.Current.Response.ContentType = "application/vnd.ms-xls";
StringWriter stringWrite = new StringWriter();
HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
DataGrid dg = new DataGrid();
dg.DataSource = ds;
dg.DataBind();
dg.RenderControl(htmlWrite);
HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=" + HttpUtility.UrlEncode(now.ToString() + ".xls"));
HttpContext.Current.Response.Write(style);
HttpContext.Current.Response.Write(stringWrite.ToString());
HttpContext.Current.Response.End();
}
public override void VerifyRenderingInServerForm(Control control)
{
}
--------------------编程问答--------------------
也可以用页面导出:
string fileName = HttpUtility.UrlEncode("Excel文件名为中文哦.xls");
Response.Clear();
Response.Buffer = true;
Response.AppendHeader("Content-Disposition", "attachment;filename=" + fileName);
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.ContentType = "application/vnd.ms-excel";
this.EnableViewState = false;
补充:.NET技术 , ASP.NET