]> source.dussan.org Git - poi.git/commitdiff
Fixed bug 51533 - Avoid exception when changing name of a sheet containing shared...
authorYegor Kozlov <yegor@apache.org>
Wed, 20 Jul 2011 09:42:31 +0000 (09:42 +0000)
committerYegor Kozlov <yegor@apache.org>
Wed, 20 Jul 2011 09:42:31 +0000 (09:42 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1148673 13f79535-47bb-0310-9956-ffa450edef68

src/documentation/content/xdocs/status.xml
src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFFormulaUtils.java
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java
src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java
src/testcases/org/apache/poi/ss/usermodel/BaseTestWorkbook.java

index 2452027a51d6ba8c3d191d0af91b0f93c2f8497c..967461af680c398ec927db4b5158caa666a32075 100644 (file)
@@ -34,6 +34,7 @@
 
     <changes>
         <release version="3.8-beta4" date="2011-??-??">
+           <action dev="poi-developers" type="fix">51533 - Avoid exception when changing name of a sheet containing shared formulas</action>
            <action dev="poi-developers" type="add">Support for appending images to existing drawings in HSSF</action>
            <action dev="poi-developers" type="fix">Added initial support for bookmarks in HWFP</action>
            <action dev="poi-developers" type="fix">46250 - Fixed cloning worksheets with images</action>
index cc354f277a8e788e17af824e999b8894148de4dd..5161160c771a56c7aac7b1f4309a232798204c39 100644 (file)
@@ -120,7 +120,7 @@ public final class XSSFFormulaUtils {
         CTCellFormula f = cell.getCTCell().getF();
         if (f != null) {
             String formula = f.getStringValue();
-            if (formula != null) {
+            if (formula != null && formula.length() > 0) {
                 int sheetIndex = _wb.getSheetIndex(cell.getSheet());
                 Ptg[] ptgs = FormulaParser.parse(formula, _fpwb, FormulaType.CELL, sheetIndex);
                 String updatedFormula = FormulaRenderer.toFormulaString(frwb, ptgs);
index 5642f26f250bf8fad235c634e930ac5f9e697ee0..526ab9224a3338ac842ff39dd4bb697f69c00a2a 100644 (file)
@@ -428,4 +428,8 @@ public final class TestXSSFWorkbook extends BaseTestWorkbook {
         assertFalse(wb.getForceFormulaRecalculation());
     }
 
+    public void testChangeSheetNameWithSharedFormulas() {
+        changeSheetNameWithSharedFormulas("shared_formulas.xlsx");
+    }
+
 }
index 4832f9f01475e82e2b9f0197563cc46aff1711f0..68ec3b2260ce55a3a4bd05f512520afbf40e5812 100644 (file)
@@ -713,4 +713,9 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
             assertEquals(3, bse.getRef());
         }
     }
+
+    public void testChangeSheetNameWithSharedFormulas() {
+        changeSheetNameWithSharedFormulas("shared_formulas.xls");
+    }
+
 }
index 9ba714c74805ab676db3da53349f8410ed027a28..b0bd1910ad622fe8e442e1950eea5a4694ca6fcc 100644 (file)
@@ -568,4 +568,28 @@ public abstract class BaseTestWorkbook extends TestCase {
         assertEquals(6.0, evaluator.evaluate(cell2).getNumberValue());
     }
 
+    public void changeSheetNameWithSharedFormulas(String sampleFile){
+        Workbook wb = _testDataProvider.openSampleWorkbook(sampleFile);
+
+        FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator();
+
+        Sheet sheet = wb.getSheetAt(0);
+
+        for (int rownum = 1; rownum <= 40; rownum++) {
+            Cell cellA = sheet.getRow(1).getCell(0);
+            Cell cellB = sheet.getRow(1).getCell(1);
+
+            assertEquals(cellB.getStringCellValue(), evaluator.evaluate(cellA).getStringValue());
+        }
+
+        wb.setSheetName(0, "Renamed by POI");
+        evaluator.clearAllCachedResultValues();
+
+        for (int rownum = 1; rownum <= 40; rownum++) {
+            Cell cellA = sheet.getRow(1).getCell(0);
+            Cell cellB = sheet.getRow(1).getCell(1);
+
+            assertEquals(cellB.getStringCellValue(), evaluator.evaluate(cellA).getStringValue());
+        }
+    }
 }