views:

29

answers:

1

Hi,

I am running .net 4.0 asp.net app on IIS 7. I want to know if there is an easy way of adding rows to an excel 2007/2010 (not too fussed) template file that a user can download from the server.

For example, the user might check a couple of tick boxes and clicks a button on the web page. The server does a sql query on a table and comes back with the results. I have an excel file with some headings, column titles, formatting etc. on the web app's resources directory. I want to make a copy of this file, insert each of the results as a row into this file (insert first name into cell A3, last name into cell B3 etc.). And make it available for the user to save on their disk.

Since Excel (xls) format is an "Open format", I was wondering how easy/straight forward this would be. Is it a matter of loading the excel XML DOM and inserting XML elements? What are libraries I need to use?

Any help or resources would be greatly appreciated.

+1  A: 

I did exactly this using an Excel template. You'll see how easy it is to do this using open source libraries as NPOI.

These links should help you get there:

Create Excel (.XLS and .XLSX) file from C#

Creating Excel spreadsheets .XLS and .XLSX in C#

Leniel Macaferi
Sweet. NPOI was the way to go. It only does Excel 2003, but its fine. I think the ExcelPackage tool has a bug where it throws a null reference during Save(). It also forces you to save the file on the server whereas NPOI can stream.
Chaitanya