开发者

NPOI HSSF vs SS namespace

开发者 https://www.devze.com 2023-01-18 00:58 出处:网络
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:

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();
        HSSF开发者_如何学编程Sheet 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 ?


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.


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);

0

精彩评论

暂无评论...
验证码 换一张
取 消