Bug 58778 - Override built-in number format
Summary: Override built-in number format
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: 3.14-dev
Hardware: PC Linux
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
Depends on:
Reported: 2015-12-28 23:07 UTC by Javen O'Neal
Modified: 2015-12-29 00:19 UTC (History)
0 users


Note You need to log in before you can comment on or make changes to this bug.
Description Javen O'Neal 2015-12-28 23:07:36 UTC
It looks like POI cannot override a built-in number format. The workbook must have been saved (by Excel) with an overridden built-in number format.

From http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDataFormat.java?revision=1721923&view=markup#l35
> global String poundFmt = "\"\u00a3\"#,##0;[Red]\\-\"\u00a3\"#,##0";
> global short expectedPoundFmtIdx = 6;
> // Read in a workbook where a currency format has been overridden to use the £ symbol in place of the $ symbol. The default built-in format is "$#,##0_);[Red]($#,##0)"
> XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("49928.xlsx"); 
> DataFormat dataFormat = wb.createDataFormat();
> short poundFmtIdx = wb.getSheetAt(0).getRow(0).getCell(0).getCellStyle().getDataFormat();
> assertEquals(poundFmtIdx, dataFormat.getFormat(poundFmt));

This could be fixed by adding
void XSSFDataFormat#putFormat(int index, String format).
Am I correct that it isn't possible to override custom data formats in XSSFWorkbooks in POI?

I'm also curious why the built-in formats don't have a leading opening parentheses. Seems like they should match up. If so, that could be a different bug.
Comment 1 Javen O'Neal 2015-12-29 00:19:45 UTC
Patch applied in r1722043.
Docs updated in r1722044.

Please revert this patch if there is already a way to override built-in number formats in POI.