|Summary:||HSSFDataFormatter returns wrongly formatted string, and does not use the default number format set by user for cell with with invalid cell format|
|Component:||HSSF||Assignee:||POI Developers List <dev>|
|Attachments:||Sample spreadsheet with a numeric cell A1 set with format = "@".|
Description Babu 2009-05-05 06:07:05 UTC
Created attachment 23612 [details] Sample spreadsheet with a numeric cell A1 set with format = "@". Create a numeric cell with a number in it and specify its format as Text ("@"). Excel will still display the number using the "General" format. (Assuming the number was 2345, Excel displays "2345"). However, if you use the HSSFDataFormatter.formatCellvalue() method, the string returned is "2345.0" which means the returned value is formatted using the String.valueOf() function of Java. (Sample spreadsheet attached) Calling the HSSFDataFormatter.createFormat(cell) with this cell returns null since the format string "@" is not a valid numeric formatter. In such a scenario one would expect HSSFDataFormatter to either use the "General" format (which is what Excel does) or to at least use the default format if set by the user using the HSSFDataFormatter.setDefaultNumberFormat() method. It does neither, and uses String.valueOf instead. No workaround except to check for this situation externally and avoid using HSSFDataFormatter's formatCellValue() method in such a situation.
Comment 1 Nick Burch 2009-05-16 10:39:48 UTC
Thanks for the bug report, now fixed in svn