Bug 50756 - XLS file with style of GENERAL changes behaviour of DataFormatter
Summary: XLS file with style of GENERAL changes behaviour of DataFormatter
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: POI Overall (show other bugs)
Version: 3.7-FINAL
Hardware: PC All
: P2 minor (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-02-10 13:45 UTC by JF
Modified: 2011-02-11 07:32 UTC (History)
1 user (show)



Attachments
File which reproduces the problem (11.00 KB, application/vnd.ms-excel)
2011-02-10 13:45 UTC, JF
Details

Note You need to log in before you can comment on or make changes to this bug.
Description JF 2011-02-10 13:45:52 UTC
Created attachment 26635 [details]
File which reproduces the problem

I have a spreadsheet created and edited with a mix or Excel 2007 and OpenOffice 3.2.1 build 9502
When I read numbers with org.apache.poi.ss.usermodel.DataFormatter (from poi-src-3.7-20101029.zip) which are shown as formatted with Format code General I get them returned in decimal format, even when they are shown as Integers. i.e. the old 12 being passed back as 12.0. I tracked the problem down to what is returned as the cell.getCellStyle().getDataFormatString() in the private Format getFormat(Cell cell) of the DataFormatter class. This returns "GENERAL" not "General" for some reason (OpenOffice seems to have changed it) so the part of the code in private Format getFormat(double cellValue, int formatIndex, String formatStr)  which handles the General style nicely;

if ("General".equals(formatStr) || "@".equals(formatStr)) {
            if (DataFormatter.isWholeNumber(cellValue)) {
                return generalWholeNumFormat;
            }
            return generalDecimalNumFormat;
        }

is never called. 

N.B. I do not get this problem with files purely edited by Excel or OpenOffice, it only seems to appear when I mix and match...
Comment 1 Nick Burch 2011-02-11 07:32:05 UTC
Fixed in r1069775.