Bug 47889 - NumberFormatException when calling XSSFCell.getStringCellValue() on cell with a string
Summary: NumberFormatException when calling XSSFCell.getStringCellValue() on cell with...
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: 3.5-dev
Hardware: PC Linux
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
Depends on:
Reported: 2009-09-22 19:01 UTC by Jeffrey Armstrong
Modified: 2009-09-26 04:05 UTC (History)
0 users

Problematic worksheet (3.47 KB, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet)
2009-09-22 19:01 UTC, Jeffrey Armstrong

Note You need to log in before you can comment on or make changes to this bug.
Description Jeffrey Armstrong 2009-09-22 19:01:29 UTC
Created attachment 24303 [details]
Problematic worksheet

When loading the example worksheet (see attached) using POI 3.5beta6, a call to
getStringCellValue results in a number formal exception for cell A1 (first row,
first column).  This cell contains the letter 'a' only.  While the worksheet is
created with Gnumeric, it does load properly in Gnumeric and OpenOffice.

The following is the exception:

java.lang.NumberFormatException: For input string: "a"
    at java.lang.Integer.parseInt(Integer.java:481)
    at java.lang.Integer.parseInt(Integer.java:514)

The call on line 225 seems to suggest that the cell is identified as containing
a string.
Comment 1 Jeffrey Armstrong 2009-09-23 04:12:32 UTC
Also tested the attached worksheet under Microsoft Office Excel 2007.  File seems to open fine there as well.
Comment 2 Yegor Kozlov 2009-09-26 04:05:23 UTC
Quite an interesting case. 

Firstly, Gnumeric seems to store strings in cells with type="str" which according to the spec means "cached formula result". Both Excel and OpenOffice tolerate it and detect such cells as of type 'string' even if the actual formula is not assigned. I fixed POI to tolerate such worksheets too. 

The second problem is that workbooks created by Gnumeric  don't contain any defined styles, that is, styles.xml is present but it is empty. This can crop up in many places as cell.getCellStyle() is supposed to return a not-null value. 
I made sure that XSSFCell.toString() works - there is a call of getCellStyle() which resulted in exception.  

The fix was committed in r819106