简体   繁体   English

在asp.net c中导出到excel时出错

[英]Error during export to excel in asp.net c#

Am getting an error when I export dynamically created html table to excel. 将动态创建的html表导出到excel时出现错误。 the error says 错误说

Missing File: ~\Temporary Internet Files\Content.IE5\style.css. 

when I say ok then the excel opens with the data displayed on browser. 当我说确定时,Excel将打开浏览器上显示的数据。 Don't know where am going wrong. 不知道哪里出错了。 Below is the code to excel export. 以下是excel导出的代码。

Response.ContentType = "application/x-msexcel";
Response.Clear();
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.AddHeader("Content-Disposition", "attachment; filename=ExcelFilenew.xls"); 
StringWriter tw = new StringWriter(); 
HtmlTextWriter hw = new HtmlTextWriter(tw);
HtmlTbl.RenderControl(hw);
Response.Write(tw.ToString());
Response.End();

You must do your export to XLS file and the whole XLS(x?) file creation on the server side. 您必须在服务器端导出到XLS文件并创建整个XLS(x?)文件。 This way as you do it you are probably trying to open HTML as XLS file at the client. 这样,您可能正在尝试在客户端将HTML作为XLS文件打开。

Create your XLSX file completely on the server side using some library like EPPlus and then send the resulting file to the client as a Response of ContentType = application/x-msexcel or better see this answer for what type of response you should use. 使用某些库(如EPPlus)在服务器端完全创建XLSX文件,然后将结果文件作为ContentType = application/x-msexcel的响应发送到客户端,或者更好地查看此答案 ,了解您应该使用哪种类型的响应。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM