Browse Source

Fixed bug 51533 - Avoid exception when changing name of a sheet containing shared formulas

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1148673 13f79535-47bb-0310-9956-ffa450edef68
tags/REL_3_8_BETA4
Yegor Kozlov 13 years ago
parent
commit
f804dd9e7b

+ 1
- 0
src/documentation/content/xdocs/status.xml View 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>

+ 1
- 1
src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFFormulaUtils.java View 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);

+ 4
- 0
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java View File

@@ -428,4 +428,8 @@ public final class TestXSSFWorkbook extends BaseTestWorkbook {
assertFalse(wb.getForceFormulaRecalculation());
}

public void testChangeSheetNameWithSharedFormulas() {
changeSheetNameWithSharedFormulas("shared_formulas.xlsx");
}

}

+ 5
- 0
src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java View File

@@ -713,4 +713,9 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
assertEquals(3, bse.getRef());
}
}

public void testChangeSheetNameWithSharedFormulas() {
changeSheetNameWithSharedFormulas("shared_formulas.xls");
}

}

+ 24
- 0
src/testcases/org/apache/poi/ss/usermodel/BaseTestWorkbook.java View 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());
}
}
}

Loading…
Cancel
Save