Bug 58778

Summary: Override built-in number format
Product: POI Reporter: Javen O'Neal <onealj>
Component: XSSFAssignee: POI Developers List <dev>
Status: RESOLVED FIXED    
Severity: normal    
Priority: P2    
Version: 3.14-dev   
Target Milestone: ---   
Hardware: PC   
OS: Linux   

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.