This project is read-only.

use to create xls file from .net table using NPOI

Nov 13, 2012 at 5:52 PM
Edited Nov 13, 2012 at 6:41 PM


using 2010

I have a .net datatable and I would like to create an excel (xls) file using NPOI.   While I am displaying most of the columns to the user, also I would like to format a couple of the columns so I can hide the columns but the value is still in the cell.

Essentially when the user clicks on the go button I want to take the .net datatable, create the excel file and then open the excel file so the user can see it and the do whatever with it, save it or edit it.

are there are any code samples of how to do this?  I just downloaded NPOI today and have not used it before.

I added the NPOI.dll to my bin and added a reference to it.  also I added Imports to NPOI in my page.  then I found this code snippet online but this will not compile because I am getting an error that "NPOI export is not defined" when I try to instantiate my object.  what I have for now is this, first line causing compile error:

        Using exporter = New NpoiExport()
            exporter.ExportDataTableToWorkbook(dtTable, "Results")

            Dim saveAsFileName As String = String.Format("Results-{0:d}.xls", DateTime.Now)

            Response.ContentType = "application/"
            Response.AddHeader("Content-Disposition", String.Format("attachment;filename={0}", saveAsFileName))
        End Using



Nov 29, 2012 at 9:42 PM

I have never seen NpoiExport class before. It should be a third-party wrapper for NPOI. Please reference the third-party document.