]> source.dussan.org Git - poi.git/commitdiff
added Workbook.getForceFormulaRecalculation as requested in Bug 51422
authorYegor Kozlov <yegor@apache.org>
Thu, 30 Jun 2011 15:54:04 +0000 (15:54 +0000)
committerYegor Kozlov <yegor@apache.org>
Thu, 30 Jun 2011 15:54:04 +0000 (15:54 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1141585 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java
src/java/org/apache/poi/ss/usermodel/Sheet.java
src/java/org/apache/poi/ss/usermodel/Workbook.java
src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFWorkbook.java
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java
src/testcases/org/apache/poi/hssf/model/TestWorkbook.java

index 6b3348aa4609f32c67750d457811eabb32ed5732..178bb37a4f368ff4d495857b396863d06f1e7492 100644 (file)
@@ -1792,4 +1792,16 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
         recalc.setEngineId(0);
     }
 
+    /**
+     * Whether Excel will be asked to recalculate all formulas when the  workbook is opened.
+     *
+     * @since 3.8
+     */
+    public boolean getForceFormulaRecalculation(){
+        InternalWorkbook iwb = getWorkbook();
+        RecalcIdRecord recalc = (RecalcIdRecord)iwb.findFirstRecordBySid(RecalcIdRecord.sid);
+        return recalc != null && recalc.getEngineId() != 0;
+    }
+
+
 }
index bb4810f50b629a658e52bbc04400bea389b02b2a..b7c145c26d76f0e19dfd3cac6880024b41ef6d13 100644 (file)
@@ -319,7 +319,7 @@ public interface Sheet extends Iterable<Row> {
     void setForceFormulaRecalculation(boolean value);
 
     /**
-     * Whether Excel will be asked to recalculate all formulas when the
+     * Whether Excel will be asked to recalculate all formulas in this sheet when the
      *  workbook is opened.  
      */
     boolean getForceFormulaRecalculation();
index 6ca460168a70fa14fba6a4bf29b93fcf619c6f55..3ee44fdc1f7fc4ed82b6d43e2a99ed421cf41bab 100644 (file)
@@ -564,4 +564,11 @@ public interface Workbook {
      */
     public void setForceFormulaRecalculation(boolean value);
 
+    /**
+     * Whether Excel will be asked to recalculate all formulas when the  workbook is opened.
+     *
+     * @since 3.8
+     */
+    boolean getForceFormulaRecalculation();
+
 }
index 6ca1f51e6ae05f3e5ba13ac630eb900262b5e5fa..6ba4137b542f60a64d59893153db63b6155a8ef7 100644 (file)
@@ -835,5 +835,12 @@ public class SXSSFWorkbook implements Workbook
         _wb.setForceFormulaRecalculation(value);
     }
 
+    /**
+     * Whether Excel will be asked to recalculate all formulas when the  workbook is opened.
+     */
+    public boolean getForceFormulaRecalculation(){
+        return _wb.getForceFormulaRecalculation();
+    }
+
 //end of interface implementation
 }
index 95cbe735989487c92b9422acd1fd81a8b7cda1f8..d8689d87ad441658bed18417d810ca3825fb9b67 100644 (file)
@@ -1596,4 +1596,16 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X
         // in the workbook the next time the file is opened.
         calcPr.setCalcId(0);
     }
+
+    /**
+     * Whether Excel will be asked to recalculate all formulas when the  workbook is opened.
+     *
+     * @since 3.8
+     */
+    public boolean getForceFormulaRecalculation(){
+        CTWorkbook ctWorkbook = getCTWorkbook();
+        CTCalcPr calcPr = ctWorkbook.getCalcPr();
+        return calcPr != null && calcPr.getCalcId() != 0;
+    }
+
 }
index a4ab3bb712684df3ed7737b8c8dd25803c614591..5642f26f250bf8fad235c634e930ac5f9e697ee0 100644 (file)
@@ -410,6 +410,7 @@ public final class TestXSSFWorkbook extends BaseTestWorkbook {
 
     public void testRecalcId() {
         XSSFWorkbook wb = new XSSFWorkbook();
+        assertFalse(wb.getForceFormulaRecalculation());
         CTWorkbook ctWorkbook = wb.getCTWorkbook();
         assertFalse(ctWorkbook.isSetCalcPr());
 
@@ -420,8 +421,11 @@ public final class TestXSSFWorkbook extends BaseTestWorkbook {
         assertEquals(0, (int) calcPr.getCalcId());
 
         calcPr.setCalcId(100);
+        assertTrue(wb.getForceFormulaRecalculation());
+
         wb.setForceFormulaRecalculation(true); // resets the EngineId flag to zero
         assertEquals(0, (int) calcPr.getCalcId());
+        assertFalse(wb.getForceFormulaRecalculation());
     }
 
 }
index 897fba1ae6eb7f6180e1ae6da4d94b8b8552739c..d8aa165f5c79f515e830cc5b2082c441df613648 100644 (file)
@@ -119,6 +119,8 @@ public final class TestWorkbook extends TestCase {
 
     public void testRecalcId(){
         HSSFWorkbook wb = new HSSFWorkbook();
+        assertFalse(wb.getForceFormulaRecalculation());
+
         InternalWorkbook iwb = TestHSSFWorkbook.getInternalWorkbook(wb);
         int countryPos = iwb.findFirstRecordLocBySid(CountryRecord.sid);
         assertTrue(countryPos != -1);
@@ -133,8 +135,10 @@ public final class TestWorkbook extends TestCase {
 
         record.setEngineId(100);
         assertEquals(100, record.getEngineId());
+        assertTrue(wb.getForceFormulaRecalculation());
 
         wb.setForceFormulaRecalculation(true); // resets the EngineId flag to zero
         assertEquals(0, record.getEngineId());
+        assertFalse(wb.getForceFormulaRecalculation());
     }
 }