You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ni...@apache.org on 2011/04/21 13:52:52 UTC

svn commit: r1095667 - in /poi/trunk/src: documentation/content/xdocs/status.xml java/org/apache/poi/ss/usermodel/Sheet.java ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java

Author: nick
Date: Thu Apr 21 11:52:52 2011
New Revision: 1095667

URL: http://svn.apache.org/viewvc?rev=1095667&view=rev
Log:
Add get/setForceFormulaRecalculation for XSSF, and promote the methods to the common usermodel Sheet, using sheetCalcPr fullCalcOnLoad="true"

Modified:
    poi/trunk/src/documentation/content/xdocs/status.xml
    poi/trunk/src/java/org/apache/poi/ss/usermodel/Sheet.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java

Modified: poi/trunk/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/status.xml?rev=1095667&r1=1095666&r2=1095667&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Thu Apr 21 11:52:52 2011
@@ -34,6 +34,7 @@
 
     <changes>
         <release version="3.8-beta3" date="2011-??-??">
+           <action dev="poi-developers" type="add">Add get/setForceFormulaRecalculation for XSSF, and promote the methods to the common usermodel Sheet</action>
            <action dev="poi-developers" type="fix">Tweak the logic for sizing the HSSFCells array on a HSSFRow to reduce memory over allocation in many use cases</action>
            <action dev="poi-developers" type="add">49765 - Support for adding a picture to a XSSFRun</action>
            <action dev="poi-developers" type="fix">Rename/Move xssf.model.Table to xssf.usermodel.XSSFTable as it now has usermodel-like features</action>

Modified: poi/trunk/src/java/org/apache/poi/ss/usermodel/Sheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/usermodel/Sheet.java?rev=1095667&r1=1095666&r2=1095667&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/usermodel/Sheet.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/usermodel/Sheet.java Thu Apr 21 11:52:52 2011
@@ -259,6 +259,21 @@ public interface Sheet extends Iterable<
     Iterator<Row> rowIterator();
 
     /**
+     * Control if Excel should be asked to recalculate all formulas when the
+     *  workbook is opened. 
+     * Calculating the formula values with {@link FormulaEvaluator} is the
+     *  recommended solution, but this may be used for certain cases where
+     *  evaluation in POI is not possible.
+     */
+    void setForceFormulaRecalculation(boolean value);
+
+    /**
+     * Whether Excel will be asked to recalculate all formulas when the
+     *  workbook is opened.  
+     */
+    boolean getForceFormulaRecalculation();
+    
+    /**
      * Flag indicating whether the sheet displays Automatic Page Breaks.
      *
      * @param value <code>true</code> if the sheet displays Automatic Page Breaks.

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java?rev=1095667&r1=1095666&r2=1095667&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java Thu Apr 21 11:52:52 2011
@@ -46,6 +46,7 @@ import org.apache.poi.ss.usermodel.CellS
 import org.apache.poi.ss.usermodel.DataValidation;
 import org.apache.poi.ss.usermodel.DataValidationHelper;
 import org.apache.poi.ss.usermodel.Footer;
+import org.apache.poi.ss.usermodel.FormulaEvaluator;
 import org.apache.poi.ss.usermodel.Header;
 import org.apache.poi.ss.usermodel.Row;
 import org.apache.poi.ss.usermodel.Sheet;
@@ -89,6 +90,7 @@ import org.openxmlformats.schemas.spread
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRow;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSelection;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheet;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetCalcPr;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetData;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetFormatPr;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetPr;
@@ -1455,6 +1457,41 @@ public class XSSFSheet extends POIXMLDoc
     }
 
     /**
+     * Control if Excel should be asked to recalculate all formulas when the
+     *  workbook is opened, via the "sheetCalcPr fullCalcOnLoad" option.
+     * Calculating the formula values with {@link FormulaEvaluator} is the
+     *  recommended solution, but this may be used for certain cases where
+     *  evaluation in POI is not possible.
+     */
+    public void setForceFormulaRecalculation(boolean value) {
+       if(worksheet.isSetSheetCalcPr()) {
+          // Change the current setting
+          CTSheetCalcPr calc = worksheet.getSheetCalcPr();
+          calc.setFullCalcOnLoad(value);
+       }
+       else if(value) {
+          // Add the Calc block and set it
+          CTSheetCalcPr calc = worksheet.addNewSheetCalcPr();
+          calc.setFullCalcOnLoad(value);
+       }
+       else {
+          // Not set, requested not, nothing to do
+       }
+    }
+
+    /**
+     * Whether Excel will be asked to recalculate all formulas when the
+     *  workbook is opened.  
+     */
+    public boolean getForceFormulaRecalculation() {
+       if(worksheet.isSetSheetCalcPr()) {
+          CTSheetCalcPr calc = worksheet.getSheetCalcPr();
+          return calc.getFullCalcOnLoad();
+       }
+       return false;
+    }
+    
+    /**
      * @return an iterator of the PHYSICAL rows.  Meaning the 3rd element may not
      * be the third row if say for instance the second row is undefined.
      * Call getRowNum() on each row if you care which one it is.



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org