poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ye...@apache.org
Subject svn commit: r1005726 - in /poi/trunk: src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDataFormat.java src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDataFormat.java test-data/spreadsheet/49928.xlsx
Date Fri, 08 Oct 2010 08:26:57 GMT
Author: yegor
Date: Fri Oct  8 08:26:57 2010
New Revision: 1005726

URL: http://svn.apache.org/viewvc?rev=1005726&view=rev
Log:
allow overridden built-in formats in XSSFCellStyle, see Bugzilla 49928 

Added:
    poi/trunk/test-data/spreadsheet/49928.xlsx   (with props)
Modified:
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDataFormat.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDataFormat.java

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDataFormat.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDataFormat.java?rev=1005726&r1=1005725&r2=1005726&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDataFormat.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDataFormat.java Fri Oct  8
08:26:57 2010
@@ -51,8 +51,8 @@ public class XSSFDataFormat implements D
      * @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;
     }
 }

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDataFormat.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDataFormat.java?rev=1005726&r1=1005725&r2=1005726&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDataFormat.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDataFormat.java Fri
Oct  8 08:26:57 2010
@@ -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 ex
 	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));
+
+    }
 }

Added: poi/trunk/test-data/spreadsheet/49928.xlsx
URL: http://svn.apache.org/viewvc/poi/trunk/test-data/spreadsheet/49928.xlsx?rev=1005726&view=auto
==============================================================================
Binary file - no diff available.

Propchange: poi/trunk/test-data/spreadsheet/49928.xlsx
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message