poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r1677371 - in /poi/trunk/src/ooxml: java/org/apache/poi/xssf/usermodel/ testcases/org/apache/poi/xssf/usermodel/
Date Sun, 03 May 2015 08:10:07 GMT
Author: nick
Date: Sun May  3 08:10:07 2015
New Revision: 1677371

URL: http://svn.apache.org/r1677371
Log:
Avoid short wrapping on cell styles and formats > 32,767 in XSSF - format supports up to
64,000 of them #57880

Modified:
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDataFormat.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java?rev=1677371&r1=1677370&r2=1677371&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java Sun May  3 08:10:07
2015
@@ -603,6 +603,9 @@ public class XSSFCellStyle implements Ce
     public short getIndex() {
         return (short)this._cellXfId;
     }
+    protected int getUIndex() {
+        return this._cellXfId;
+    }
 
     /**
      * Get the color to use for the left border
@@ -974,6 +977,15 @@ public class XSSFCellStyle implements Ce
      * @param fmt the index of a data format
      */
     public void setDataFormat(short fmt) {
+        // XSSF supports >32,767 formats
+        setDataFormat(fmt&0xffff);
+    }
+    /**
+     * Set the index of a data format
+     *
+     * @param fmt the index of a data format
+     */
+    public void setDataFormat(int fmt) {
         _cellXf.setApplyNumberFormat(true);
         _cellXf.setNumFmtId(fmt);
     }

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=1677371&r1=1677370&r2=1677371&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 Sun May  3
08:10:07 2015
@@ -51,6 +51,14 @@ 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) {
+        return getFormat(index&0xffff);
+    }
+    /**
+     * get the format string that matches the given format index
+     * @param index of a format
+     * @return string represented at index of format or null if there is not a  format at
that index
+     */
+    public String getFormat(int index) {
         String fmt = stylesSource.getNumberFormatAt(index);
         if(fmt == null) fmt = BuiltinFormats.getBuiltinFormat(index);
         return fmt;

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java?rev=1677371&r1=1677370&r2=1677371&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java Sun May  3 08:10:07
2015
@@ -843,6 +843,15 @@ public class XSSFWorkbook extends POIXML
      */
     @Override
     public XSSFCellStyle getCellStyleAt(short idx) {
+        return getCellStyleAt(idx&0xffff);
+    }
+    /**
+     * Get the cell style object at the given index
+     *
+     * @param idx  index within the set of styles
+     * @return XSSFCellStyle object at the index
+     */
+    public XSSFCellStyle getCellStyleAt(int idx) {
         return stylesSource.getStyleAt(idx);
     }
 

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java?rev=1677371&r1=1677370&r2=1677371&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java Sun May
 3 08:10:07 2015
@@ -2439,4 +2439,39 @@ public final class TestXSSFBugs extends
         
         wb.close();
     }
+    
+    /**
+     * .xlsx supports 64000 cell styles, the style indexes after
+     *  32,767 must not be -32,768, then -32,767, -32,766
+     */
+    @Test
+    public void bug57880() throws Exception {
+        int numStyles = 33000;
+        XSSFWorkbook wb = new XSSFWorkbook();
+        XSSFSheet s = wb.createSheet("TestSheet");
+        XSSFDataFormat fmt = wb.getCreationHelper().createDataFormat();
+        for (int i=1; i<numStyles; i++) {
+            short df = fmt.getFormat("test"+i);
+            // Format indexes will be wrapped beyond 32,676
+            assertEquals(164+i, df&0xffff);
+            // Create a style and use it
+            XSSFCellStyle style = wb.createCellStyle();
+            assertEquals(i, style.getUIndex());
+            style.setDataFormat(df);
+            XSSFCell c = s.createRow(i).createCell(0, Cell.CELL_TYPE_NUMERIC);
+            c.setCellStyle(style);
+            c.setCellValue(i);
+        }
+        
+        wb = XSSFTestDataSamples.writeOutAndReadBack(wb);
+        fmt = wb.getCreationHelper().createDataFormat();
+        s = wb.getSheetAt(0);
+        for (int i=1; i<numStyles; i++) {
+            XSSFCellStyle style = wb.getCellStyleAt((short)i);
+            assertNotNull(style);
+            assertEquals(i, style.getUIndex());
+            assertEquals(164+i, style.getDataFormat()&0xffff);
+            assertEquals("test"+i, style.getDataFormatString());
+        }
+    }
 }



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


Mime
View raw message