|Summary:||NumberFormatException when calling XSSFCell.getStringCellValue() on cell with a string|
|Product:||POI||Reporter:||Jeffrey Armstrong <jeff>|
|Component:||XSSF||Assignee:||POI Developers List <dev>|
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.NumberFormatException.forInputString(NumberFormatException.java:65) at java.lang.Integer.parseInt(Integer.java:481) at java.lang.Integer.parseInt(Integer.java:514) at org.apache.poi.xssf.usermodel.XSSFCell.getRichStringCellValue(XSSFCell.java:257) at org.apache.poi.xssf.usermodel.XSSFCell.getStringCellValue(XSSFCell.java:225) ... 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 Regards, Yegor