导出超过10k条记录到excel返回“找不到文件错误” [英] Export more than 10k records to excel returns "file not found error"

查看:148
本文介绍了导出超过10k条记录到excel返回“找不到文件错误”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用下面的代码将数据表导出到excel,如果行数小于10k并且它抛出404 - 找不到文件或目录,它就可以正常工作。如果记录数超过10k限制则出错。如果有任何关于如何解决此问题的想法,请告诉我。





DataTable dt = GetDataFromDB();

HtmlForm form = new HtmlForm();

form.Attributes [runat] =server;

Response.Clear();

Response.AddHeader(content-disposition,attachment; filename = Test.xls);

Response.Charset =;

Response.ContentType =application / vnd.xls;

StringWriter stringWrite = new StringWriter();

HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);

form.Controls.Add(dt);

this.Controls.Add(form);

form.RenderControl(htmlWrite);

回复.Write(stringWrite.ToString());

Response.End();



提前致谢,



Vasanth



我尝试了什么:



我也尝试导出.csv格式但同样的问题。

I am using below code to export datatable to excel and it just works fine if the rows count is less than 10k and it throws "404 - File or directory not found." error if records count exceeds 10k limit. Please let me know if any idea on how to solve this.


DataTable dt= GetDataFromDB();
HtmlForm form = new HtmlForm();
form.Attributes["runat"] = "server";
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=Test.xls");
Response.Charset = "";
Response.ContentType = "application/vnd.xls";
StringWriter stringWrite = new StringWriter();
HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
form.Controls.Add(dt);
this.Controls.Add(form);
form.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();

Thanks in advance,

Vasanth

What I have tried:

I tried to export to .csv format also but same issue.

推荐答案

您实际上没有将任何内容导出为Excel文件。你正在做的是导出一个带有xls扩展名的html,当在Excel中打开时,它将呈现为原生的xls文件。



你应该做什么正在导出到本机Excel文档。有几个免费和商业图书馆可以帮助解决这个问题。



几个好的免费图书馆是:



EPPlus - EPPlus - 在服务器上创建高级Excel电子表格 - 主页 [ ^ ]

OpenXML SDK - 欢迎使用Open XML SDK 2.5 for Office [ ^ ]



如果你能看到商业产品,我建议你看看Aspose 。伟大的产品已经存在了好几年。



要避免的一个产品是Office Interop。甚至MS也不建议在今天的环境中使用它。
You are really not exporting anything as an Excel file. What you are doing is exporting an html with an "xls" extension that when opened in Excel would render as a native "xls" file.

What you should be doing is exporting to a native Excel document. There are several free and commercial libraries to help with this.

A couple a good free one are:

EPPlus - EPPlus-Create advanced Excel spreadsheets on the server - Home[^]
OpenXML SDK - Welcome to the Open XML SDK 2.5 for Office[^]

If you are able to look at commercial products I would recommend looking at Aspose. Great product that has been around for several year.

The one product to avoid is Office Interop. Even MS does not recommend using this in today environments.


默认大小为4MB。所以我们可以在web.config中增加大小(最大限制)

The default size is 4MB. So we can increase the size (max limit) in the web.config
<configuration>
  <system.web>
    <httpRuntime maxRequestLength="xxx" />
  </system.web>
</configuration>




请点击以下链接:

asp.net - 超出最大请求长度 [ ^ ]



我预计这将成为问题。请检查一次。

谢谢



Please follow the below link:
asp.net - Maximum request length exceeded[^]

I anticipate this would be the issue. Please check once.
Thanks


这篇关于导出超过10k条记录到excel返回“找不到文件错误”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆