views:

394

answers:

4

Does anyone know of resources that can help me export simple contents of a GridView to a native Excel 2007 format (i.e. the OpenOfficeXML format).

I've already seen solutions like Matt Berseth's, and in fact I have been using that for a while, but it comes with an annoying warning produced by Excel 2007 as documented here stemming from the fact that a native Excel file is not generated; rather it is HTML.

My initial research shows that, at the core, xlsx files are zip files, but I have no idea how to produce these or what goes in them.

Any suggestions (or tutorials) would be greatly appreciated.

A: 

CarlosAg has an ExcelXML writer which works really well. It isn't a native excel 2007 formatted file, but it will be readable in excel 2007.

You will need to write a little method to do the exporting manually, the API is very straight forward though. You will create a sheet object, then a row object, then a cell object. You can just loop through your data and output it. The examples on the site are pretty decent.

Bob
+1  A: 

Have you looked at this article?

Magnus Johansson
Boy, this looks great! Couple of comments got me worried about the license, but I checked it out, and it seems fine for our use. Barring a miracle, this seems like a winner. Thanks Magnus!
Matthew Jones
A: 

I prefer using Microsoft's own Open XML Format SDK. It is free, it is released by Microsoft and it creates real .xlsx files.

You can find the reference documentation here, as you can see, it is pretty straightforward to use.

DrJokepu
I probably should have clarified that we are using .NET 2.0, so this solution will not work.
Matthew Jones
A: 

SpreadsheetGear for .NET can read and write native xls and xlsx files and is easier to use (takes less of your time) than other solutions because it has an Excel like API so you don't have to learn anything about Open XML.

You can see some live ASP.NET (C# and VB) Excel Reporting examples here and download an evaluation version here.

Disclaimer: I own SpreadsheetGear LLC

Joe Erickson