Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to programmatically create a "true" Excel file [duplicate]

Possible Duplicate:
Generating an Excel file in ASP.NET

Here's my question: How do you programmatically create a "true" Excel file?

Note: I don't mean a CSV, HTML/CSS, or XML file, I mean a file written in the same format Excel uses to save spreadsheets.

Background: I'm working on an ASP.Net application, which includes Telerik's RadGrid. We're currently using the RadGrid's ExportToExcel() function, but some of our customers need to be able to view these exports using Excel Viewer. Telerik's function exports an HTML/CSS-based file, which the full-version of Excel can open, but Excel Viewer cannot.

I'm sure its possible to programmatically create a "true" Excel file, but I'm not sure where to begin. Is there an SDK which could help me do this?

Any suggestions would be appreciated. Thanks in advance.

like image 635
ks78 Avatar asked Apr 05 '12 20:04

ks78


4 Answers

You can use the interop from Excel like RedFilter showed you, but there are also open source alternatives that does not require Excel to be installed on your pc to work. It can be useful if you have a asp.net project deployed on a server that does not have Excel.

EPPlus is a good library. http://epplus.codeplex.com/

Personnally, I use Koogra. http://sourceforge.net/projects/koogra/?_test=b

like image 55
Amaranth Avatar answered Oct 23 '22 15:10

Amaranth


You can obtain the Office File Formats specs from Microsoft, but the binary formats are hideously complex in places. You could probably get away with a minimal implementation though. Here is the .xls binary file format spec. I would suggest using the new XML formats used by Office 2007 and 2010 - See this WikiPedia article on the Office Open XML standard.

The only other option that comes to mind is automating Excel and getting it to produce the file.

like image 20
Bork Blatt Avatar answered Oct 23 '22 15:10

Bork Blatt


You can use interop (as described in another answer), but you it's not officially supported in server environment.

Another solution would be using OpenXML SDK 2.0, which should allow you to create XLSX files. It can be downloaded from here: http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=5124. If you decided to use this solution, I recommend to take a look at OpenXML SDK 2.0 Productivity Tool available there as well.

like image 42
Lukasz M Avatar answered Oct 23 '22 16:10

Lukasz M


Apache POI is a popular and reliable Java library for writing Excel files. NPOI is another good option (http://npoi.codeplex.com) to write Excel files with .NET.

like image 30
bouvierr Avatar answered Oct 23 '22 15:10

bouvierr