asp.net-mvc 在 Asp.net MVC 中导出到 Excel
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/301986/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Export to Excel in Asp.net MVC
提问by BigJoe714
I am working on an ASP.NET MVC application where I need to export data to an excel spreadsheet. Previously, in webforms apps, I used some code I found to render a GridView as an excel-compatible file. This was quite handy. I was wondering what the quickest/most effective method would be to do this in MVC. Thanks.
我正在开发一个 ASP.NET MVC 应用程序,我需要将数据导出到 Excel 电子表格。以前,在 webforms 应用程序中,我使用了一些我发现的代码将 GridView 呈现为与 excel 兼容的文件。这很方便。我想知道在 MVC 中最快/最有效的方法是什么。谢谢。
采纳答案by sgwill
One simple option would be to create a view to render an XML-version of an Excel File. You could either use the new Office 2007 version, or the older 2003 version. We chose the 2003 version so that more people could use it, but that's up to you, of course.
一个简单的选择是创建一个视图来呈现 Excel 文件的 XML 版本。您可以使用新的 Office 2007 版本或旧的 2003 版本。我们选择了 2003 版本,以便更多人可以使用它,当然,这取决于您。
回答by BigJoe714
Here is a blog post from Stephen Walther entitled ASP.NET MVC Tip #2 - Create a custom Action Result that returns Microsoft Excel Documents
这是 Stephen Walther 的一篇博文,题为ASP.NET MVC Tip #2 - Create a custom Action Result that return Microsoft Excel Documents

