views:

139

answers:

1

I have an asp.net website that will generate some excel files with 7-8 sheets of data. The best solution so far seems to be NPOI, this can create excel files without installing excel on the server, and has a nice API simillar to the excel interop.

However i can't find a way to dump an entire datatable in excel similar to CopyFromRecordset

Any tips on how to do that , or a better solution than NPOI ?

+1  A: 

I think NPOI is a good solution, you do not want to be doing interop with Office on a server based environment like ASP.NET, it is just not designed for it and it will fail. In fact MS does not support this, I will update with a link.

As for NPOI our team has used it for something very similar and I know that they wrote a routine to dump the datatable so I assume that this means NPOI does not have that capability natively.

Basically what you will need to do is enumerate the values in each row of the DataTable and write the value out, it should be a reasonably simple routine to write.

Update: The link I promised.

http://support.microsoft.com/kb/257757

A key phrase from the above link

Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.

Chris Taylor
thanks for the quick answer, i will try to iterate through the datatable then, my biggest fear is that this will be slow.How are things going with your project in terms of speed ?Some of the sheets will have over 30k rows in my case.
Iulian
@Iulian, I will check with the team since I am not involved with the code, but if there were performance complaints I would have heard about it. If you make efficient use of NPOI I do not see why it should be slow, like most things I am sure there is the right way to do it and the wrong way, so the trick will be finding the most appropriate way to write bulk data to NPOI, I will check with the team tomorrow and post back here.
Chris Taylor
wow, it's actually blazing fast, it's generating my excel files instantly.
Iulian