.net 导出excel时,excel的临时文件不存放在服务器上,.NET 中Excel导出文件问题!1 文件名称或路径不存在2 文件正被其他程序使用。 3 您正要保存的工作簿与当前打开的工作簿同名。...

.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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值