monitorjbl / excel-streaming-reader

An easy-to-use implementation of a streaming Excel reader using Apache POI
Apache License 2.0
953 stars 344 forks source link

Fix NumberFormatException with malformed SST reference #93

Closed ms1111 closed 7 years ago

ms1111 commented 7 years ago

Cells of type "s" (shared string reference) have an integer value that is a lookup into the shared string table.

If a cell is of type "s", and the value ( tag) is blank, the StreamingExcelReader throws a NumberFormatException in StreamingSheetReader.unformattedContents():

int idx = Integer.parseInt(lastContents);

This happens if you have a cell that looks like this:

Normally, if Excel saves the file, that whole <c ...> wouldn't even be there, but I've seen this happen twice now for data files from different sources.

So unformattedContents() needs to check if the "lastContents" is null first. This is effectively what the regular POI XSSF reader does - it checks "isSetV()".

monitorjbl commented 7 years ago

Looks good to me, thanks for including a unit test!