从数据表导出npoi
我有一个 ASP.NET 网站,它将生成一些包含 7-8 张数据的 Excel 文件。 目前为止最好的解决方案似乎是NPOI,这样可以在不安装excel的情况下创建excel文件在服务器上,并且有一个类似于 excel 互操作的很好的 API。
但是,我找不到类似于 CopyFromRecordset 的方法在 excel 中转储整个数据表。有关
如何执行此操作的任何提示,或者比 NPOI 更好的解决方案?
I have an asp.net website that will generate some excel files with 7-8 sheets of data.
The best solution so far seems to be NPOI, this can create excel files without installing excel on the server, and has a nice API simillar to the excel interop.
However i can't find a way to dump an entire datatable in excel similar to CopyFromRecordset
Any tips on how to do that , or a better solution than NPOI ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为 NPOI 是一个很好的解决方案,您不想在基于服务器的环境(如 ASP.NET)上与 Office 进行互操作,它不是为此设计的,并且会失败。事实上MS不支持这个,我会用链接更新。
至于 NPOI,我们的团队已将其用于非常类似的事情,我知道他们编写了一个例程来转储数据表,所以我认为这意味着 NPOI 本身不具备该功能。
基本上,您需要做的是枚举数据表每一行中的值并将该值写出来,这应该是一个相当简单的例程。
更新:我承诺的链接。
http://support.microsoft.com/kb/257757
上述链接中的关键短语
< strong>Microsoft 当前不建议也不支持从任何无人值守、非交互式客户端应用程序或组件(包括 ASP、ASP.NET、DCOM 和 NT 服务)实现 Microsoft Office 应用程序的自动化,因为 Office 可能会表现出不稳定的行为和/或在此环境中运行 Office 时出现死锁。
I think NPOI is a good solution, you do not want to be doing interop with Office on a server based environment like ASP.NET, it is just not designed for it and it will fail. In fact MS does not support this, I will update with a link.
As for NPOI our team has used it for something very similar and I know that they wrote a routine to dump the datatable so I assume that this means NPOI does not have that capability natively.
Basically what you will need to do is enumerate the values in each row of the DataTable and write the value out, it should be a reasonably simple routine to write.
Update: The link I promised.
http://support.microsoft.com/kb/257757
A key phrase from the above link
Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.