Bug 47154 - HSSFDataFormatter returns wrongly formatted string, and does not use the default number format set by user for cell with with invalid cell format
Summary: HSSFDataFormatter returns wrongly formatted string, and does not use the defa...
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 3.2-FINAL
Hardware: PC Linux
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-05-05 06:07 UTC by Babu
Modified: 2009-05-16 10:39 UTC (History)
0 users



Attachments
Sample spreadsheet with a numeric cell A1 set with format = "@". (6.50 KB, application/octet-stream)
2009-05-05 06:07 UTC, Babu
Details

Note You need to log in before you can comment on or make changes to this bug.
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