Exception when loading a specific xls file (1.2.5)

Oct 30, 2012 at 1:39 PM

Hi all.  I'm using Tim Claason's ExcelWrapper in front of NPOI 1.2.5 - thanks Tim and NPOI team!  (I've modified ExcelWrapper slightly to fix some incompatibilities with NPOI 1.2.5, and also to support writing numeric values as well as strings to the sheet.)

Running into an issue when trying to open some specific Excel files.  I get an exception when creating a new HSSFWorkbook from a stream (or rather, when the ExcelWrapper does this):

Exception: Unexpected record type (StringRecord) 

Stack:    
  at NPOI.HSSF.Record.Aggregates.RowRecordsAggregate..ctor(RecordStream rs, SharedValueManager svm)
    in ...\NPOI_ExcelLibrary\src\HSSF\Record\Aggregates\RowRecordsAggregate.cs:line 178
  at NPOI.HSSF.Model.InternalSheet..ctor(RecordStream rs)
    in ...\NPOI_ExcelLibrary\src\HSSF\Model\InternalSheet.cs:line 246
  at NPOI.HSSF.Model.InternalSheet.CreateSheet(RecordStream rs)
    in ...\NPOI_ExcelLibrary\src\HSSF\Model\InternalSheet.cs:line 172
  at NPOI.HSSF.UserModel.HSSFWorkbook..ctor(DirectoryNode directory, Boolean preserveNodes)
    in ...\NPOI_ExcelLibrary\src\HSSF\UserModel\HSSFWorkbook.cs:line 313
  at NPOI.HSSF.UserModel.HSSFWorkbook..ctor(DirectoryNode directory, POIFSFileSystem fs, Boolean preserveNodes)
    in ...\NPOI_ExcelLibrary\src\HSSF\UserModel\HSSFWorkbook.cs:line 263
  at NPOI.HSSF.UserModel.HSSFWorkbook..ctor(POIFSFileSystem fs, Boolean preserveNodes)
    in ...\NPOI_ExcelLibrary\src\HSSF\UserModel\HSSFWorkbook.cs:line 202
  at NPOI.HSSF.UserModel.HSSFWorkbook..ctor(Stream s, Boolean preserveNodes)
    in ...\NPOI_ExcelLibrary\src\HSSF\UserModel\HSSFWorkbook.cs:line 344
  at NPOI.HSSF.UserModel.HSSFWorkbook..ctor(Stream s)
    in ...\NPOI_ExcelLibrary\src\HSSF\UserModel\HSSFWorkbook.cs:line 325
  at SSExcelLoader.ExcelWrapper.openWorkbook()
    in ...\SSExcelLoader\SSExcelLoader\ExcelWrapper.cs:line 108

Currently, I'm able to work around this exception by opening the offending workbook in Excel, doing File -> Save As, XLS, and saving it to a different file name.  Then I can open the newly-saved workbook without issue (so far).

Problem is, I can't automate the above workaround, and my project is editing multiple files copied down from several different locations.  It's a pain to have to watch for this issue and manually 'recover' the file with the Excel Save As workaround.  Has anyone else seen this issue?

Thanks,
Ryan 

Oct 30, 2012 at 1:57 PM

Here are DropBox links to two files for testing.
The 'boom' file causes the exception, and the 'resaved' file does not.

https://dl.dropbox.com/u/97970347/TaskFile60-boom.xls

https://dl.dropbox.com/u/97970347/TaskFile60-resaved.xls

Thanks,
Ryan

Coordinator
Nov 6, 2012 at 7:15 PM

There must be something wrong in the RowRecords of the before-saved file. Where is the file from? Is it generated by third-party component?

Nov 6, 2012 at 7:27 PM

After asking the creator of the third-party software that is also interacting with this Excel file, I found that it uses the "Excel API .NET" component from http://www.skysof.com/ - so yes, a third-party component is generating the file.

Coordinator
Nov 22, 2012 at 9:12 PM

If that's the case, please ask the third-party for help. They are making mistakes while creating the file instead of NPOI.