Bug 53389 - DataFormatter not removing locale for number cell
Summary: DataFormatter not removing locale for number cell
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: POI Overall (show other bugs)
Version: 3.8-FINAL
Hardware: PC Windows XP
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-06-08 20:09 UTC by Robert Kish
Modified: 2012-06-12 22:11 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Robert Kish 2012-06-08 20:09:04 UTC
The DataFormatter is not removing the locale when given the format string [$-1010409]General for a number cell. The resulting format String is "General", but is applied too late.

In org.apache.poi.ss.usermodel.DataFormatter.getFormat(double, int, String), at the end of the function, createFormat is called. However, if the resulting format is "General" (or I assume "@" also), the logic a couple lines earlier to return generalWholeNumFormat or generalDecimalNumFormat does not apply. If the code were rearranged to apply this check (again?) after createFormat is called, then a valid format could be used.

For the Junit, org.apache.poi.ss.usermodel.TestDataFormatter, (I stuck it in testOther), you can add the following to demonstrate this case:

assertEquals("63", dfUS.formatRawCellContents(63.0, -1, "[$-1010409]General"));

I expect "63". The code outputs "General".
Comment 1 Nick Burch 2012-06-10 23:36:42 UTC
Is the lack of locale removal only affecting the General case, or does it apply to all formats (custom and built in)?

(This should help us work out what area to focus on)
Comment 2 Robert Kish 2012-06-11 14:22:51 UTC
(In reply to comment #1)
> Is the lack of locale removal only affecting the General case, or does it
> apply to all formats (custom and built in)?
> 
> (This should help us work out what area to focus on)

General and @ are the ones not working as expected. Other formats, such as ## and 00 are working fine when a locale is present.

These 2 fail:
assertEquals("63", dfUS.formatRawCellContents(63.0, -1, "[$-1010409]General"));
assertEquals("63", dfUS.formatRawCellContents(63.0, -1, "[$-1010409]@"));

These 2 are fine:
assertEquals("63", dfUS.formatRawCellContents(63.0, -1, "[$-1010409]##"));
assertEquals("63", dfUS.formatRawCellContents(63.0, -1, "[$-1010409]00"));        

I put all 4 formats in Excel 2003, and when saved to CSV, they export as "63".
Comment 3 Nick Burch 2012-06-12 22:11:13 UTC
Fixed in r1349562, and unit tests added based on your supplied example ones, thanks!