aboutsummaryrefslogtreecommitdiffstats
path: root/src/ooxml/java
diff options
context:
space:
mode:
authorNick Burch <nick@apache.org>2011-05-09 14:04:21 +0000
committerNick Burch <nick@apache.org>2011-05-09 14:04:21 +0000
commite94feeee12d4356cf5e46b44894032b64f6d0110 (patch)
tree54b43348d22e8048c721aeacc11fd282a9ce8f27 /src/ooxml/java
parent888645dd3f8c50579d47dd9d7bb174b10c38cff8 (diff)
downloadpoi-e94feeee12d4356cf5e46b44894032b64f6d0110.tar.gz
poi-e94feeee12d4356cf5e46b44894032b64f6d0110.zip
As Java doesn't allow static methods on interfaces, allow HSSFFormulaEvaluator or XSSFFormulaEvaluator to generically recalculate all formulas in a workbook
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1101033 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/ooxml/java')
-rw-r--r--src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFormulaEvaluator.java42
1 files changed, 22 insertions, 20 deletions
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFormulaEvaluator.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFormulaEvaluator.java
index 6d2583b90d..3f8ce85a63 100644
--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFormulaEvaluator.java
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFormulaEvaluator.java
@@ -17,21 +17,19 @@
package org.apache.poi.xssf.usermodel;
-import java.util.Iterator;
-
+import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator;
+import org.apache.poi.ss.formula.IStabilityClassifier;
+import org.apache.poi.ss.formula.WorkbookEvaluator;
import org.apache.poi.ss.formula.eval.BoolEval;
import org.apache.poi.ss.formula.eval.ErrorEval;
import org.apache.poi.ss.formula.eval.NumberEval;
import org.apache.poi.ss.formula.eval.StringEval;
import org.apache.poi.ss.formula.eval.ValueEval;
import org.apache.poi.ss.formula.udf.UDFFinder;
-import org.apache.poi.ss.formula.IStabilityClassifier;
-import org.apache.poi.ss.formula.WorkbookEvaluator;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellValue;
import org.apache.poi.ss.usermodel.FormulaEvaluator;
-import org.apache.poi.ss.usermodel.Row;
-import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Workbook;
/**
* Evaluates formula cells.<p/>
@@ -46,6 +44,7 @@ import org.apache.poi.ss.usermodel.Sheet;
public class XSSFFormulaEvaluator implements FormulaEvaluator {
private WorkbookEvaluator _bookEvaluator;
+ private XSSFWorkbook _book;
public XSSFFormulaEvaluator(XSSFWorkbook workbook) {
this(workbook, null, null);
@@ -59,9 +58,11 @@ public class XSSFFormulaEvaluator implements FormulaEvaluator {
@Deprecated
public XSSFFormulaEvaluator(XSSFWorkbook workbook, IStabilityClassifier stabilityClassifier) {
_bookEvaluator = new WorkbookEvaluator(XSSFEvaluationWorkbook.create(workbook), stabilityClassifier, null);
+ _book = workbook;
}
private XSSFFormulaEvaluator(XSSFWorkbook workbook, IStabilityClassifier stabilityClassifier, UDFFinder udfFinder) {
_bookEvaluator = new WorkbookEvaluator(XSSFEvaluationWorkbook.create(workbook), stabilityClassifier, udfFinder);
+ _book = workbook;
}
/**
@@ -234,21 +235,22 @@ public class XSSFFormulaEvaluator implements FormulaEvaluator {
* cells, and calling evaluateFormulaCell on each one.
*/
public static void evaluateAllFormulaCells(XSSFWorkbook wb) {
- XSSFFormulaEvaluator evaluator = new XSSFFormulaEvaluator(wb);
- for(int i=0; i<wb.getNumberOfSheets(); i++) {
- Sheet sheet = wb.getSheetAt(i);
-
- for (Iterator<Row> rit = sheet.rowIterator(); rit.hasNext();) {
- Row r = rit.next();
-
- for (Iterator cit = r.cellIterator(); cit.hasNext();) {
- XSSFCell c = (XSSFCell) cit.next();
- if (c.getCellType() == XSSFCell.CELL_TYPE_FORMULA)
- evaluator.evaluateFormulaCell(c);
- }
- }
- }
+ HSSFFormulaEvaluator.evaluateAllFormulaCells((Workbook)wb);
}
+ /**
+ * Loops over all cells in all sheets of the supplied
+ * workbook.
+ * For cells that contain formulas, their formulas are
+ * evaluated, and the results are saved. These cells
+ * remain as formula cells.
+ * For cells that do not contain formulas, no changes
+ * are made.
+ * This is a helpful wrapper around looping over all
+ * cells, and calling evaluateFormulaCell on each one.
+ */
+ public void evaluateAll() {
+ HSSFFormulaEvaluator.evaluateAllFormulaCells(_book);
+ }
/**
* Returns a CellValue wrapper around the supplied ValueEval instance.