Using NPOI.SS.UserModel to open both XLS and XLSX for reading

Nov 14, 2012 at 10:12 PM

Using NPOI 2.0 Alpha

I am having an issue opening an Excel 2007 (xlsx) Workbook.  I receive the following error:

The supplied data appears to be in the Office 2007+ XML. You are calling the part of POI that deals with OLE2 Office Documents. You need to call a different part of POI to process this data (eg XSSF instead of HSSF)

The error is occurring on the following line (yes, VB.NET)

        Dim xlWB As IWorkbook = DirectCast(WorkbookFactory.Create(New POIFSFileSystem(New FileStream(Me.solFilePath, FileMode.Open, FileAccess.Read))), XSSFWorkbook)

I know that NPOI is modeled after Apache POI, and I have used Apache POI's SS UserModel to read both xls and xlsx files in Java without having to change anything.  As you can see above, I tried to cast it to an XSSFWorkbook, but that didn't work either.  What am I doing wrong, or is the SS UserModel in NPOI not capable of reading both xls and xlsx?

Nov 14, 2012 at 10:35 PM

Nevermind.  I just figured it out.  Instead of using POIFSFileSystem, just supply the FileStream directly to WorkbookFactory.Create(...) and it seems to work just fine.

Dim xlWB As IWorkbook = WorkbookFactory.Create(New FileStream(Me.solFilePath, FileMode.Open, FileAccess.Read))

 Sorry for the false alarm.

Dec 3, 2012 at 8:13 PM

I've referenced in the 2.0 .dll and it doesn't appear WorkbookFactory is present.  I've imported the following: NPOI.SS and SS.UserModel.  It also appears that XSSFWorkbook has been removed as well.  I need to read an xlsx and grab some values.  Any suggestions would be greatly appreciated. 

Dec 3, 2012 at 8:36 PM

I've referenced in the 2.0 .dll and it doesn't appear WorkbookFactory is present.  I've imported the following: NPOI.SS and SS.UserModel.  It also appears that XSSFWorkbook has been removed as well.  I need to read an xlsx and grab some values.  Any suggestions would be greatly appreciated.

Coordinator
Dec 6, 2012 at 12:16 AM

NPOI.OOXML should be referenced.

Feb 5, 2013 at 6:54 PM
Edited Feb 12, 2013 at 4:04 PM
I've referenced NPOI.OOXML but the dll does not have a strong name so I cannot deploy it to the GAC (for a few different reasons, I do need to deploy it to the GAC). The other npoi dlls, npoi.dll, NPOI.OpenXml4Net.dll, NPOI.OpenXmlFormats.dll all have strong names, just not NPOI.OOXML.dll.

Could we get a version of the dll with a strong name please? Thanks.

[Updated] The .Net4 version is strongly named, it's just the .Net2 version that is not strongly named.