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.
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
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With