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

鸿与黑 2013-08-13 04:16:01
在做导出Excel问题的时候,本地里面能够试验成功,但是发布到了服务器上文件就导出失败了,
错误提示是:
1 文件名称或路径不存在
2 文件正被其他程序使用
3 您正要保存的工作簿与当前打开的工作簿同名

尝试过各种办法
如在"DCOM配置"中找到"Microsoft Excel 应用程序",在它上面点击右键"等等此类解决方法,都不行。

在此希望朋友们给个建议,到底怎么改才能导出成功!
...全文
1272 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
全栈极简 2013-08-13
  • 打赏
  • 举报
回复
也可以用页面导出:
    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;  
generhappy 2013-08-13
  • 打赏
  • 举报
回复
调用这个把 骚年!


private void DataSetToExcel(string FileName,DataSet ds)
        {

            string style = "<style>td{mso-number-format:\"\\@\";}</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)
        {
        }

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧