Question

I'm trying to use the NPOI library in a winforms app. I have referenced the latest NPOI dll in my project and tried to reproduce the examples gave by NPOI and found on SO:

        HSSFWorkbook workbook = new HSSFWorkbook();
        HSSFSheet sheet = workbook.CreateSheet("Sheet1");
        HSSFRow headerRow = sheet.CreateRow(0);

But this won't compile on my machine because HSSFWorkbook.CreateSheet() returns a NPOI.SS.UserModel.Sheet instead of a NPOI.SS.UserModel.HSSFSheet.

What am I missing here ?

Was it helpful?

Solution

Try the following:

Sheet sheet = workbook.CreateSheet("Sheet1");
Row headerRow = sheet.CreateRow(0);

And include the namespace NPOI.SS.UserModel

Sheet and Row are actually interfaces, but don't have the I prefix (I presume) because this library is a port from Java.

OTHER TIPS

The interface is prepared for NPOI 2.0 actually. In NPOI 2.0, there are two namespace: XSSF and HSSF. XSSF is for xlsx, HSSF is for xls. Both implements interfaces in NPOI.SS.

using NPOI.SS.UserModel; ... ISheet sheet = workbook.CreateSheet("Sheet1"); IRow headerRow = sheet.CreateRow(0);

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top