I am making a Windows Forms application in Visual Studio 2010 with a very low framework ( 2.0 ). This application must generate a report ( Excel ) with data extracted from a database.
I tried various libraries but they required framework from 4.0 onwards, so I opted to use NPOI . The detail is that I don't know which version it can accept without problems with the required framework since from version 2.0 of NPOI it provides more namespaces.
Could someone explain to me what I should use to create an excel report with NPOI .
This website is a great resource for anyone starting out with
POI
orNPOI
.It's a quick overview of the basic functions from the docs
POI
, like reading a named range, collapsing rows, etc. SinceNPOI
it is a close match toPOI
, the guide is quite effective.Busy Developers Guide to HSSF and XSSF Functions
Create a new file
.xlsx
usingNPOI
and write to it, here is the code:Another example:
Edit existing excel file with C# NPOI:
The simplest and easiest solution: open the file to read, create
HSSFWorkbook
, do whatever you want in that workbook, and then open the file again to write to it.It's safe to use
hssfwb
out of scopeusing
becauseHSSFWorkbook
it contains no reference to the file it was read from (as long as you see it in sourcesNPOI
).So the code could look like this:
In addition to other links that may be of interest:
I hope it helps you, Greetings!