]> source.dussan.org Git - poi.git/commitdiff
Bugzilla 53950 - fixed setForceFormulaRecalculation to reset workbook-level manual...
authorYegor Kozlov <yegor@apache.org>
Thu, 4 Oct 2012 13:26:44 +0000 (13:26 +0000)
committerYegor Kozlov <yegor@apache.org>
Thu, 4 Oct 2012 13:26:44 +0000 (13:26 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1394059 13f79535-47bb-0310-9956-ffa450edef68

src/documentation/content/xdocs/status.xml
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java

index 90fdb8838c1fc57becec987a1d4489d6539814d4..69870b19c5f989d67f4f0d35811b93fb51d93a1c 100644 (file)
@@ -34,6 +34,7 @@
 
     <changes>
         <release version="3.9-beta1" date="2012-??-??">
+          <action dev="poi-developers" type="fix">53950 - fixed setForceFormulaRecalculation to reset workbook-level "manual" flag</action>
           <action dev="poi-developers" type="fix">52211 - avoid unnessary re-coverting content types to US-ASCII, it can cause exceptions on ibm mainframes</action>
           <action dev="poi-developers" type="fix">53568 - Set shapes anchors in XSSF when reading from existing drawings</action>
           <action dev="poi-developers" type="add">HSSFOptimiser will now also tidy away un-used cell styles, in addition to duplicate styles</action>
index ccf2419873a4d9bc93812e2b566eb6002af06c75..438b1ef328216236958488a73c2615e28cefef4f 100644 (file)
@@ -1502,7 +1502,9 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
      * @see org.apache.poi.ss.usermodel.Workbook#setForceFormulaRecalculation(boolean)
      */
     public void setForceFormulaRecalculation(boolean value) {
-       if(worksheet.isSetSheetCalcPr()) {
+        CTCalcPr calcPr = getWorkbook().getCTWorkbook().getCalcPr();
+
+        if(worksheet.isSetSheetCalcPr()) {
           // Change the current setting
           CTSheetCalcPr calc = worksheet.getSheetCalcPr();
           calc.setFullCalcOnLoad(value);
@@ -1512,9 +1514,10 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
           CTSheetCalcPr calc = worksheet.addNewSheetCalcPr();
           calc.setFullCalcOnLoad(value);
        }
-       else {
-          // Not set, requested not, nothing to do
-       }
+        if(value && calcPr != null && calcPr.getCalcMode() == STCalcMode.MANUAL) {
+            calcPr.setCalcMode(STCalcMode.AUTO);
+        }
+
     }
 
     /**
index 639a78d4238a7a34959b2ec74df8f6c987635d89..f50c42a1502a30a86e1597322336b24f57a1b476 100644 (file)
@@ -1672,6 +1672,10 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X
         // when set to 0, will tell Excel that it needs to recalculate all formulas
         // in the workbook the next time the file is opened.
         calcPr.setCalcId(0);
+
+        if(value && calcPr.getCalcMode() == STCalcMode.MANUAL) {
+            calcPr.setCalcMode(STCalcMode.AUTO);
+        }
     }
 
     /**
index 141a06fdbf43580d5f4cbcc05cd0fd46e3a4aa0d..e47632acf9eb0f1b889e4fbaa37e11341cabb560 100644 (file)
@@ -1074,11 +1074,18 @@ public final class TestXSSFSheet extends BaseTestSheet {
          // Set
          sheet.setForceFormulaRecalculation(true);
          assertEquals(true, sheet.getForceFormulaRecalculation());
-         
-         // Check
+
+        // calcMode="manual" is unset when forceFormulaRecalculation=true
+        CTCalcPr calcPr = workbook.getCTWorkbook().addNewCalcPr();
+        calcPr.setCalcMode(STCalcMode.MANUAL);
+        sheet.setForceFormulaRecalculation(true);
+        assertEquals(STCalcMode.AUTO, calcPr.getCalcMode());
+
+        // Check
          sheet.setForceFormulaRecalculation(false);
          assertEquals(false, sheet.getForceFormulaRecalculation());
-         
+
+
          // Save, re-load, and re-check
          workbook = XSSFTestDataSamples.writeOutAndReadBack(workbook);
          sheet = workbook.getSheet("Sheet 1");
index 3a755d37fd6b8eafd5cfca1d7de9a77145c68577..60ad9fbbdbe1a80ce3a5bb7a2fdfd3391d6f1b76 100644 (file)
@@ -35,6 +35,7 @@ import org.apache.poi.xssf.model.StylesTable;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCalcPr;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbook;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbookPr;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.STCalcMode;
 
 public final class TestXSSFWorkbook extends BaseTestWorkbook {
 
@@ -426,6 +427,12 @@ public final class TestXSSFWorkbook extends BaseTestWorkbook {
         wb.setForceFormulaRecalculation(true); // resets the EngineId flag to zero
         assertEquals(0, (int) calcPr.getCalcId());
         assertFalse(wb.getForceFormulaRecalculation());
+
+        // calcMode="manual" is unset when forceFormulaRecalculation=true
+        calcPr.setCalcMode(STCalcMode.MANUAL);
+        wb.setForceFormulaRecalculation(true);
+        assertEquals(STCalcMode.AUTO, calcPr.getCalcMode());
+
     }
 
     public void testChangeSheetNameWithSharedFormulas() {