There's a number of ways to "export" data to Excel from an ASP.NET site - some more elegant than others.
有多种方法可以将数据从ASP.NET站点“导出”到Excel,其中有些方法比其他方法更优雅。
Gross: You can use ASP.NET to generate a CSV file of Mime Type text/plain or text/csv and write it back to the browser.
毛重:您可以使用ASP.NET生成Mime类型为text / plain或text / csv的CSV文件,并将其写回到浏览器。
NOT Gross: You can use ASP.NET to generate an XML-SS (Excel XML Spreadsheet) document and write it back to the browser.
无需花钱:您可以使用ASP.NET生成XML-SS ( Excel XML电子表格)文档并将其写回到浏览器中。
Really Easy but not Really XMLy: You can take advantage of the ASP.NET DataGrid's ability to generate HTML tables quickly and return the page with a Mime Type of application/vnd.ms-excel. Here's a great example on how to create these reports.
真的很简单,但不是真正的XMLy:您可以利用ASP.NET DataGrid的功能来快速生成HTML表,并使用Mime Type of application / vnd.ms-excel返回页面。 这是有关如何创建这些报告的绝佳示例。
Easy but uses 3rd Party Control: Use ExcelWriter on the server side to create the Report.
容易,但使用第三方控制:在服务器端使用ExcelWriter创建报告。
Disgusting: Automate Excel on the ServerSide. Don't do this for Pete's Sake.
令人作呕:在ServerSide上自动执行Excel 。 不要为皮特的清酒做这个。
翻译自: https://www.hanselman.com/blog/exporting-tabular-data-to-excel-from-aspnet