从视图填充 Excel 工作簿
从视图填充 Excel 工作簿的最佳方式是什么?
我想在视图中设计一个文本框“StudentId”和一个按钮“显示成绩”。
一旦学生输入“StudentId”并单击“显示成绩”,我想从“StudentTable”中提取该特定“StudentId”的“成绩”并将其显示在 Excel 工作簿中。
我怎么能这样做呢?
提前致谢
What is the best way to populate an excel workbook from a view?
I want to design a textbox "StudentId" and a button "Show Grades" in a view.
Once a student enters "StudentId" and clicks "Show Grades" I want to pull "Grades" from "StudentTable" for that particular "StudentId" and display it in an Excel workbook.
How could I do this?
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果导出到 Excel 2007+ (.xlsx) 适合您的情况,您可以查看 EPPlus 库。这对我来说非常有效。您不需要安装 Office。
http://epplus.codeplex.com/
http://epplus.codeplex.com/wikipage?title=WebapplicationExample
If exporting to Excel 2007+ (.xlsx) is ok for your situation, you could take a look at the EPPlus library. It's worked very well for me. You don't need to have office installed.
http://epplus.codeplex.com/
http://epplus.codeplex.com/wikipage?title=WebapplicationExample
从网站导出到 Excel 可能很棘手。我还没有找到一种干净的方法来做到这一点。主要是因为它需要在服务器上安装office。
这里有一些例子。
http://forums.asp.net/t/1038105.aspx/1
http://madskristensen.net/post/Export-a-DataTable-to-Excel-in-ASPNET.aspx
但我建议简单地导出为 .csv
Exporting to excel can be tricky from a website. I have yet to find one clean way to do it. Mostly because it requires office to be installed on the server.
Here are some examples out there.
http://forums.asp.net/t/1038105.aspx/1
http://madskristensen.net/post/Export-a-DataTable-to-Excel-in-ASPNET.aspx
But I would suggest simply exporting in .csv
昂贵但非常完整的选项: Office Writer
另一个选项是填充 Gridview,然后更改然后调整响应标题让浏览器将结果下载到 Excel 工作簿。
我使用以下内容生成一个简单的电子表格:
这对服务器端根本没有额外的要求。
The expensive, but incredibly complete option: Office Writer
The other option is to populate a Gridview then change then tweak the response headers to get the browser to download the result an Excel workbook.
I use the following to produce a simple spreadsheet:
This has no extra requirements server side at all.