From 7c3ce57a613f03c578db063ecdb77db314d53e23 Mon Sep 17 00:00:00 2001 From: Yegor Kozlov Date: Fri, 8 Oct 2010 08:26:57 +0000 Subject: [PATCH] allow overridden built-in formats in XSSFCellStyle, see Bugzilla 49928 git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1005726 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/xssf/usermodel/XSSFDataFormat.java | 4 +- .../xssf/usermodel/TestXSSFDataFormat.java | 38 ++++++++++++++++++ test-data/spreadsheet/49928.xlsx | Bin 0 -> 7984 bytes 3 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 test-data/spreadsheet/49928.xlsx diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDataFormat.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDataFormat.java index 6e78cf79b..00ac90736 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDataFormat.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDataFormat.java @@ -51,8 +51,8 @@ public class XSSFDataFormat implements DataFormat { * @return string represented at index of format or null if there is not a format at that index */ public String getFormat(short index) { - String fmt = BuiltinFormats.getBuiltinFormat(index); - if(fmt == null) fmt = stylesSource.getNumberFormatAt(index); + String fmt = stylesSource.getNumberFormatAt(index); + if(fmt == null) fmt = BuiltinFormats.getBuiltinFormat(index); return fmt; } } diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDataFormat.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDataFormat.java index 963d0df2d..3769ccf19 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDataFormat.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDataFormat.java @@ -18,7 +18,10 @@ package org.apache.poi.xssf.usermodel; import org.apache.poi.ss.usermodel.BaseTestDataFormat; +import org.apache.poi.ss.usermodel.BuiltinFormats; +import org.apache.poi.ss.usermodel.DataFormatter; import org.apache.poi.xssf.XSSFITestDataProvider; +import org.apache.poi.xssf.XSSFTestDataSamples; /** * Tests for {@link XSSFDataFormat} @@ -28,4 +31,39 @@ public final class TestXSSFDataFormat extends BaseTestDataFormat { public TestXSSFDataFormat() { super(XSSFITestDataProvider.instance); } + + /** + * [Bug 49928] formatCellValue returns incorrect value for \u00a3 formatted cells + */ + public void test49928(){ + XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("49928.xlsx"); + DataFormatter df = new DataFormatter(); + + XSSFSheet sheet = wb.getSheetAt(0); + XSSFCell cell = sheet.getRow(0).getCell(0); + XSSFCellStyle style = cell.getCellStyle(); + + String poundFmt = "\"\u00a3\"#,##0;[Red]\\-\"\u00a3\"#,##0"; + // not expected normally, id of a custom format should be gerater + // than BuiltinFormats.FIRST_USER_DEFINED_FORMAT_INDEX + short poundFmtIdx = 6; + + assertEquals(poundFmt, style.getDataFormatString()); + assertEquals(poundFmtIdx, style.getDataFormat()); + assertEquals("\u00a31", df.formatCellValue(cell)); + + + XSSFDataFormat dataFormat = wb.createDataFormat(); + assertEquals(poundFmtIdx, dataFormat.getFormat(poundFmt)); + assertEquals(poundFmt, dataFormat.getFormat(poundFmtIdx)); + + // an attempt to register an existing format returns its index + assertEquals(poundFmtIdx, wb.getStylesSource().putNumberFormat(poundFmt)); + + // now create a custom format with Pound (\u00a3) + short customFmtIdx = dataFormat.getFormat("\u00a3##.00[Yellow]"); + assertTrue(customFmtIdx > BuiltinFormats.FIRST_USER_DEFINED_FORMAT_INDEX ); + assertEquals("\u00a3##.00[Yellow]", dataFormat.getFormat(customFmtIdx)); + + } } diff --git a/test-data/spreadsheet/49928.xlsx b/test-data/spreadsheet/49928.xlsx new file mode 100644 index 0000000000000000000000000000000000000000..6a49ae3a7b263b522a81566fc7c751f7a1eab54f GIT binary patch literal 7984 zcmeHMXHb*d)=oe`nn0-1J4i>m6cI!r5IWLDI!Ft>28Ga@bdV~&cPY{&R1v9>8YvHY9tyya4wr|B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