Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Export to Excel in Asp.net MVC [closed]

Tags:

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.

like image 334
BigJoe714 Avatar asked Nov 19 '08 14:11

BigJoe714


People also ask

Is closed XML free?

ClosedXML is a . NET Library for writing and manipulating the Excel 2007+ files. It's available free on GitHub to use for the commercial project.

How can create and download Excel file in ASP NET MVC?

To create new ASP.NET MVC Application, open Visual Studio 2015, move to File menu and choose New < Project. It will open “New Project” dialog Window. Thus, go to Visual C# < Web and then from the right pane, just choose ASP.NET Web Application. Provide the name of the Application “ExportExcelDemo” and click OK.

What is closed XML?

ClosedXML is a . NET library for reading, manipulating and writing Excel 2007+ (. xlsx, . xlsm) files. It aims to provide an intuitive and user-friendly interface to dealing with the underlying OpenXML API.


2 Answers

Here is a blog post from Stephen Walther entitled ASP.NET MVC Tip #2 - Create a custom Action Result that returns Microsoft Excel Documents

like image 145
BigJoe714 Avatar answered Sep 16 '22 20:09

BigJoe714


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.

XML 2003 ref on MSDN

XML 2007 ref on MSDN

like image 21
sgwill Avatar answered Sep 17 '22 20:09

sgwill