diff options
author | Yegor Kozlov <yegor@apache.org> | 2012-02-07 10:46:55 +0000 |
---|---|---|
committer | Yegor Kozlov <yegor@apache.org> | 2012-02-07 10:46:55 +0000 |
commit | 8840f717da8af3218c94d0d99f409ed1c77f8fe7 (patch) | |
tree | 68f6cb935feea748599528b9b6d5f9a81f4cffe0 | |
parent | 0c9d5c57e6478c6ea7200bbad405810e804e30ea (diff) | |
download | poi-8840f717da8af3218c94d0d99f409ed1c77f8fe7.tar.gz poi-8840f717da8af3218c94d0d99f409ed1c77f8fe7.zip |
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
-rw-r--r-- | src/documentation/content/xdocs/status.xml | 1 | ||||
-rw-r--r-- | src/java/org/apache/poi/hssf/record/aggregates/SharedValueManager.java | 7 | ||||
-rw-r--r-- | src/testcases/org/apache/poi/hssf/record/aggregates/TestSharedValueManager.java | 20 | ||||
-rw-r--r-- | test-data/spreadsheet/52527.xls | bin | 0 -> 33280 bytes |
4 files changed, 24 insertions, 4 deletions
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 @@ <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> 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 Binary files differnew file mode 100644 index 0000000000..b20d7d71ea --- /dev/null +++ b/test-data/spreadsheet/52527.xls |