From b9101138bdbac0dafc4267987d33ed97d6a351bb Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Sat, 30 Mar 2019 23:59:19 +0000 Subject: [PATCH] [bug-61700] getForceFormulaRecalculation() returns wrong value. Fix thanks to Kai G git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1856650 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/xssf/usermodel/XSSFWorkbook.java | 2 +- .../poi/xssf/usermodel/TestXSSFWorkbook.java | 24 ++++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java index 14ca6c97ea..f2c9635303 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java @@ -2239,7 +2239,7 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Date1904Su public boolean getForceFormulaRecalculation(){ CTWorkbook ctWorkbook = getCTWorkbook(); CTCalcPr calcPr = ctWorkbook.getCalcPr(); - return calcPr != null && calcPr.getCalcId() != 0; + return calcPr != null && calcPr.getCalcId() != 1; } diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java index 3fa007ba3e..0f39461002 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java @@ -500,7 +500,7 @@ public final class TestXSSFWorkbook extends BaseTestXWorkbook { wb.setForceFormulaRecalculation(true); // resets the EngineId flag to zero assertEquals(0, (int) calcPr.getCalcId()); - assertFalse(wb.getForceFormulaRecalculation()); + assertTrue(wb.getForceFormulaRecalculation()); // calcMode="manual" is unset when forceFormulaRecalculation=true calcPr.setCalcMode(STCalcMode.MANUAL); @@ -1143,4 +1143,26 @@ public final class TestXSSFWorkbook extends BaseTestXWorkbook { wb.close(); } + + /** + * See bug #61700 test data tables + * + * @throws Exception + */ + @Test + public void testWorkbookForceFormulaRecalculation() throws Exception { + Workbook workbook = _testDataProvider.createWorkbook(); + workbook.createSheet().createRow(0).createCell(0).setCellFormula("B1+C1"); + workbook.getCreationHelper().createFormulaEvaluator().evaluateAll(); + + assertFalse(workbook.getForceFormulaRecalculation()); + workbook.setForceFormulaRecalculation(true); + assertTrue(workbook.getForceFormulaRecalculation()); + + Workbook wbBack = _testDataProvider.writeOutAndReadBack(workbook); + assertTrue(wbBack.getForceFormulaRecalculation()); + + workbook.close(); + wbBack.close(); + } } -- 2.39.5