From: Yegor Kozlov Date: Tue, 7 Feb 2012 10:46:55 +0000 (+0000) Subject: Bugzilla 52527: avoid exception when matching shared formula records in HSSF X-Git-Tag: REL_3_8_FINAL~60 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=8840f717da8af3218c94d0d99f409ed1c77f8fe7;p=poi.git Bugzilla 52527: avoid exception when matching shared formula records in HSSF git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1241419 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index 3f0996a3fc..af3bbee4c2 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -34,6 +34,7 @@ + 52527 - avoid exception when matching shared formula records in HSSF 52568 - Added methods to set/get an XWPFRun's text color 52566 - Added methods to set/get vertical alignment and color in XWPFTableCell 52562 - Added methods to get/set a table row's Can't Split and Repeat Header attributes in XWPF diff --git a/src/java/org/apache/poi/hssf/record/aggregates/SharedValueManager.java b/src/java/org/apache/poi/hssf/record/aggregates/SharedValueManager.java index 81abdb6fd9..7f6e4022d7 100644 --- a/src/java/org/apache/poi/hssf/record/aggregates/SharedValueManager.java +++ b/src/java/org/apache/poi/hssf/record/aggregates/SharedValueManager.java @@ -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; } diff --git a/src/testcases/org/apache/poi/hssf/record/aggregates/TestSharedValueManager.java b/src/testcases/org/apache/poi/hssf/record/aggregates/TestSharedValueManager.java index 7e359a3fb1..aea5b321e3 100644 --- a/src/testcases/org/apache/poi/hssf/record/aggregates/TestSharedValueManager.java +++ b/src/testcases/org/apache/poi/hssf/record/aggregates/TestSharedValueManager.java @@ -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 index 0000000000..b20d7d71ea Binary files /dev/null and b/test-data/spreadsheet/52527.xls differ