]> source.dussan.org Git - poi.git/commitdiff
Merged revisions 638786-638802,638805-638811,638813-638814,638816-639230,639233-63924...
authorNick Burch <nick@apache.org>
Tue, 15 Jul 2008 18:56:24 +0000 (18:56 +0000)
committerNick Burch <nick@apache.org>
Tue, 15 Jul 2008 18:56:24 +0000 (18:56 +0000)
https://svn.apache.org/repos/asf/poi/trunk

........
  r676457 | josh | 2008-07-14 00:23:13 +0100 (Mon, 14 Jul 2008) | 1 line

  Fix for bug 45380 - added return keyword in ArrayPtg.toFormulaString()
........
  r676995 | yegor | 2008-07-15 19:13:50 +0100 (Tue, 15 Jul 2008) | 1 line

  fixed bug #45322: HSSFSheet.autoSizeColumn() throws NPE when cell number format was not found
........

git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@677006 13f79535-47bb-0310-9956-ffa450edef68

src/documentation/content/xdocs/changes.xml
src/documentation/content/xdocs/status.xml
src/java/org/apache/poi/hssf/record/formula/ArrayPtg.java
src/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java
src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java
src/testcases/org/apache/poi/hssf/data/45322.xls [new file with mode: 0644]
src/testcases/org/apache/poi/hssf/record/formula/TestArrayPtg.java
src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java

index 7e1ccbfba50f51efb92cf54773700fbf2e902179..1fee98e86e28ddfd867e0ff1902d0ae423d08eb3 100644 (file)
@@ -50,6 +50,8 @@
            <action dev="POI-DEVELOPERS" type="add">Created a common interface for handling Excel files, irrespective of if they are .xls or .xlsx</action>
         </release>
         <release version="3.1.1-alpha1" date="2008-??-??">
+           <action dev="POI-DEVELOPERS" type="fix">45322 - Fixed NPE in HSSFSheet.autoSizeColumn() when cell number format was not found</action>
+           <action dev="POI-DEVELOPERS" type="add">45380 - Missing return keyword in ArrayPtg.toFormulaString()</action>
            <action dev="POI-DEVELOPERS" type="add">44958 - Record level support for Data Tables. (No formula parser support though)</action>
            <action dev="POI-DEVELOPERS" type="add">35583 - Include a version class, org.apache.poi.Version, to allow easy introspection of the POI version</action>
            <action dev="POI-DEVELOPERS" type="add">Allow the cloning of one HSSFCellStyle onto another, including cloning styles from one HSSFWorkbook onto another</action>
index febf5bd1d5a4dbc1352a06da5e7ea3f91d06c162..e6472d6e9a762a982524ce99c315e773d5aa5a92 100644 (file)
@@ -47,6 +47,8 @@
            <action dev="POI-DEVELOPERS" type="add">Created a common interface for handling Excel files, irrespective of if they are .xls or .xlsx</action>
         </release>
         <release version="3.1.1-alpha1" date="2008-??-??">
+           <action dev="POI-DEVELOPERS" type="fix">45322 - Fixed NPE in HSSFSheet.autoSizeColumn() when cell number format was not found</action>
+           <action dev="POI-DEVELOPERS" type="add">45380 - Missing return keyword in ArrayPtg.toFormulaString()</action>
            <action dev="POI-DEVELOPERS" type="add">44958 - Record level support for Data Tables. (No formula parser support though)</action>
            <action dev="POI-DEVELOPERS" type="add">35583 - Include a version class, org.apache.poi.Version, to allow easy introspection of the POI version</action>
            <action dev="POI-DEVELOPERS" type="add">Allow the cloning of one HSSFCellStyle onto another, including cloning styles from one HSSFWorkbook onto another</action>
index 371753007933db3ac9053bd1474eaf9b53ab51ee..b38bcd27de628058a0924d3a2437706f057e9bf1 100644 (file)
@@ -176,7 +176,7 @@ public final class ArrayPtg extends Ptg {
                        return ((Double)o).toString();
                }
                if (o instanceof Boolean) {
-                       ((Boolean)o).toString();
+                       return ((Boolean)o).booleanValue() ? "TRUE" : "FALSE";
                }
                if (o instanceof ErrorConstant) {
                        return ((ErrorConstant)o).getText();
index 5bf795e453ae9bd9524b0782ea12d71af0a0e96e..64c5b6df44fe061ef3d177763540f16f1ceaf8da 100644 (file)
@@ -280,21 +280,23 @@ public class HSSFCellStyle implements CellStyle
      * Get the contents of the format string, by looking up
      *  the DataFormat against the bound workbook
      * @see org.apache.poi.hssf.usermodel.HSSFDataFormat
+     * @return the format string or "General" if not found
      */
     public String getDataFormatString() {
-       HSSFDataFormat format = new HSSFDataFormat(workbook);
-       
-        return format.getFormat(getDataFormat());
+        return getDataFormatString(workbook);
     }
     /**
      * Get the contents of the format string, by looking up
      *  the DataFormat against the supplied workbook
      * @see org.apache.poi.hssf.usermodel.HSSFDataFormat
+     *
+     * @return the format string or "General" if not found
      */
     public String getDataFormatString(org.apache.poi.ss.usermodel.Workbook workbook) {
        HSSFDataFormat format = new HSSFDataFormat( ((HSSFWorkbook)workbook).getWorkbook() );
        
-        return format.getFormat(getDataFormat());
+        int idx = getDataFormat();
+        return idx == -1 ? "General" : format.getFormat(getDataFormat());
     }
     /**
      * Get the contents of the format string, by looking up
index e9e3be6b3c71442f07dbce5afe8f8a4d6e2071d1..d4bc9613d04134f2596bb83e2616175073f0d138 100644 (file)
@@ -1868,9 +1868,7 @@ public class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet
             } else {
                 String sval = null;
                 if (cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC) {
-                    HSSFDataFormat dataformat = wb.createDataFormat();
-                    short idx = style.getDataFormat();
-                    String format = dataformat.getFormat(idx).replaceAll("\"", "");
+                    String format = style.getDataFormatString().replaceAll("\"", "");
                     double value = cell.getNumericCellValue();
                     try {
                         NumberFormat fmt;
diff --git a/src/testcases/org/apache/poi/hssf/data/45322.xls b/src/testcases/org/apache/poi/hssf/data/45322.xls
new file mode 100644 (file)
index 0000000..7117214
Binary files /dev/null and b/src/testcases/org/apache/poi/hssf/data/45322.xls differ
index 2ba27e963b34a15bd8a4769809e4ea48d73a200b..14bcde38b3f8d2b08773e899f29dbd1a3a60f3df 100644 (file)
@@ -102,7 +102,7 @@ public final class TestArrayPtg extends TestCase {
        public void testElementOrderingInSpreadsheet() {
                HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("ex42564-elementOrder.xls");
 
-               // The formula has an array with 3 rows and 5 column 
+               // The formula has an array with 3 rows and 5 columns 
                String formula = wb.getSheetAt(0).getRow(0).getCell((short)0).getCellFormula();
                // TODO - These number literals should not have '.0'. Excel has different number rendering rules
 
@@ -111,4 +111,21 @@ public final class TestArrayPtg extends TestCase {
                }
                assertEquals("SUM({1.0,2.0,3.0;4.0,5.0,6.0;7.0,8.0,9.0;10.0,11.0,12.0;13.0,14.0,15.0})", formula);
        }
+
+       public void testToFormulaString() {
+               ArrayPtg ptg = new ArrayPtg(new TestcaseRecordInputStream(ArrayPtg.sid, ENCODED_PTG_DATA));
+               
+               ptg.readTokenValues(new TestcaseRecordInputStream(0, ENCODED_CONSTANT_DATA));
+               
+               String actualFormula;
+               try {
+                       actualFormula = ptg.toFormulaString(null);
+               } catch (IllegalArgumentException e) {
+                       if (e.getMessage().equals("Unexpected constant class (java.lang.Boolean)")) {
+                               throw new AssertionFailedError("Identified bug 45380");
+                       }
+                       throw e;
+               }
+               assertEquals("{TRUE,\"ABCD\";\"E\",0.0;FALSE,\"FG\"}", actualFormula);
+       }
 }
index 24d7ccfdad7adef626b48364094b6f1aa7ca8799..40e4bd34dd538b28405b54f67dcc1148c9b7e37f 100644 (file)
@@ -1354,4 +1354,13 @@ public final class TestBugs extends TestCase {
         // TODO - check the formula once tables and
         //  arrays are properly supported
     }
+
+    /**
+     * 45322: HSSFSheet.autoSizeColumn fails when style.getDataFormat() returns -1
+     */
+    public void test45322() throws Exception {
+        HSSFWorkbook wb = openSample("44958.xls");
+        HSSFSheet sh = wb.getSheetAt(0);
+        for(short i=0; i < 30; i++) sh.autoSizeColumn(i);
+     }
 }