]> source.dussan.org Git - poi.git/commitdiff
Bugzilla 52527: avoid exception when matching shared formula records in HSSF
authorYegor Kozlov <yegor@apache.org>
Tue, 7 Feb 2012 10:46:55 +0000 (10:46 +0000)
committerYegor Kozlov <yegor@apache.org>
Tue, 7 Feb 2012 10:46:55 +0000 (10:46 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1241419 13f79535-47bb-0310-9956-ffa450edef68

src/documentation/content/xdocs/status.xml
src/java/org/apache/poi/hssf/record/aggregates/SharedValueManager.java
src/testcases/org/apache/poi/hssf/record/aggregates/TestSharedValueManager.java
test-data/spreadsheet/52527.xls [new file with mode: 0644]

index 3f0996a3fcb818c011ff0ec45b851e391111ba6a..af3bbee4c2f3fc4efb84c7bf5b07f54eb6801380 100644 (file)
@@ -34,6 +34,7 @@
 
     <changes>
         <release version="3.8-beta6" date="2012-??-??">
+           <action dev="poi-developers" type="fix">52527 - avoid exception when matching shared formula records in HSSF</action>
            <action dev="poi-developers" type="add">52568 - Added methods to set/get an XWPFRun's text color</action>
            <action dev="poi-developers" type="add">52566 - Added methods to set/get vertical alignment and color in XWPFTableCell</action>
            <action dev="poi-developers" type="add">52562 - Added methods to get/set a table row's Can't Split and Repeat Header attributes  in XWPF</action>
index 81abdb6fd971864d530a0d4c171c958e207bf66f..7f6e4022d76e5b00fdd5efad155233476fd821e4 100644 (file)
@@ -158,6 +158,9 @@ public final class SharedValueManager {
         */
        public SharedFormulaRecord linkSharedFormulaRecord(CellReference firstCell, FormulaRecordAggregate agg) {
                SharedFormulaGroup result = findFormulaGroupForCell(firstCell);
+        if(null == result) {
+            throw new RuntimeException("Failed to find a matching shared formula record");
+        }
                result.add(agg);
                return result.getSFR();
        }
@@ -170,10 +173,6 @@ public final class SharedValueManager {
             }
         }
         SharedFormulaGroup sfg = _groupsCache.get(getKeyForCache(cellRef));
-        if(null == sfg) {
-            // TODO - fix file "15228.xls" so it opens in Excel after rewriting with POI
-            throw new RuntimeException("Failed to find a matching shared formula record");
-        }
         return sfg;
     }
 
index 7e359a3fb1d1b5dfb069516d800368b0fb025ba3..aea5b321e36c3bac2deb10074112950693089d84 100644 (file)
@@ -192,4 +192,24 @@ public final class TestSharedValueManager extends TestCase {
                        throw new RuntimeException(e);
                }
        }
+
+    public void testBug52527() {
+        HSSFWorkbook wb1 = HSSFTestDataSamples.openSampleWorkbook("52527.xls");
+        HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1);
+
+        assertEquals("IF(H3,LINEST(N9:N14,K9:M14,FALSE),LINEST(N8:N14,K8:M14,FALSE))",
+                wb1.getSheetAt(0).getRow(4).getCell(11).getCellFormula());
+        assertEquals("IF(H3,LINEST(N9:N14,K9:M14,FALSE),LINEST(N8:N14,K8:M14,FALSE))",
+                wb2.getSheetAt(0).getRow(4).getCell(11).getCellFormula());
+
+        assertEquals("1/SQRT(J9)",
+                wb1.getSheetAt(0).getRow(8).getCell(10).getCellFormula());
+        assertEquals("1/SQRT(J9)",
+                wb2.getSheetAt(0).getRow(8).getCell(10).getCellFormula());
+
+        assertEquals("1/SQRT(J26)",
+                wb1.getSheetAt(0).getRow(25).getCell(10).getCellFormula());
+        assertEquals("1/SQRT(J26)",
+                wb2.getSheetAt(0).getRow(25).getCell(10).getCellFormula());
+    }
 }
diff --git a/test-data/spreadsheet/52527.xls b/test-data/spreadsheet/52527.xls
new file mode 100644 (file)
index 0000000..b20d7d7
Binary files /dev/null and b/test-data/spreadsheet/52527.xls differ