How to export asp.net MVC view details to excel file?

How to export ASP.NET MVC data to excel file? In fact, my view page contains many types of views. For each cycle, I use these data types to display data on a view page. My requirement is that I want to export this display data to an Excel file. How to achieve this?

thank

0
asp.net-mvc excel
Apr 21 '10 at 10:49
source share
3 answers

Take a look at http://blogs.msdn.com/erikaehrli/archive/2009/01/30/how-to-export-data-to-excel-from-an-asp-net-application-avoid-the-file-format -differ-prompt.aspx .

After some experimentation, I am using the Open XML SDK 2.0. You can currently find a lot of information on how to do this at http://msdn.microsoft.com/en-us/office/aa905545.aspx and http://openxmldeveloper.org/ . Another http://extrememl.codeplex.com/ link may also be helpful.

Using the Open XML SDK 2.0 for the first time takes a little longer, like other methods, but the exported files are real Excel files and should not be converted by users. And if you have more requirements for the format of the created excel files, you can implement it there.

+1
Apr 21 '10 at 11:08
source share
β€” -

You can scroll the keys / values ​​of your ViewData and generate an excel file (various options mentioned here ) or just CSV

But I would recommend doing it in the controller rather and returning FileResult, and not from ViewData (which, as I believe, you use in your view).

0
Apr 21 '10 at 11:02
source share

Depending on the complexity of the page’s HTML page, you can leave by simply changing the title type to application/excel . Excel has built-in html parsing functionality. I successfully did this many times several years ago using the DataGrid on the page.

 Response.ContentType = "application/excel" Response.AppendHeader "content-disposition", "attachment: filename=TestExcelFile.xls" 

Some HTML information in excel

0
Apr 21 '10 at 11:19
source share



All Articles