diff options
author | Josh Micich <josh@apache.org> | 2008-09-23 21:52:49 +0000 |
---|---|---|
committer | Josh Micich <josh@apache.org> | 2008-09-23 21:52:49 +0000 |
commit | 57f8cb379daa50ebf6723f2ebf5309202ea71bb2 (patch) | |
tree | 93eb745c9300909e527bee02d041b09dcbd7d85d /src/java/org/apache/poi/hssf/usermodel | |
parent | 08b87dee0feb93c4ad711303fa643e207c0e72f7 (diff) | |
download | poi-57f8cb379daa50ebf6723f2ebf5309202ea71bb2.tar.gz poi-57f8cb379daa50ebf6723f2ebf5309202ea71bb2.zip |
Merged revisions 698047 via svnmerge from
https://svn.apache.org/repos/asf/poi/trunk
........
r698047 | josh | 2008-09-22 17:40:22 -0700 (Mon, 22 Sep 2008) | 1 line
Optimised the FormulaEvaluator to take cell dependencies into account
........
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@698370 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/poi/hssf/usermodel')
-rw-r--r-- | src/java/org/apache/poi/hssf/usermodel/HSSFEvaluationWorkbook.java | 8 | ||||
-rw-r--r-- | src/java/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java | 31 |
2 files changed, 23 insertions, 16 deletions
diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFEvaluationWorkbook.java b/src/java/org/apache/poi/hssf/usermodel/HSSFEvaluationWorkbook.java index 39dbdcd069..d82a9d1144 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFEvaluationWorkbook.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFEvaluationWorkbook.java @@ -73,11 +73,9 @@ public final class HSSFEvaluationWorkbook implements FormulaRenderingWorkbook, E public Sheet getSheet(int sheetIndex) {
return _uBook.getSheetAt(sheetIndex);
}
-
- public Sheet getSheetByExternSheetIndex(int externSheetIndex) {
- int sheetIndex = _iBook.getSheetIndexFromExternSheetIndex(externSheetIndex);
- return _uBook.getSheetAt(sheetIndex);
- }
+ public int convertFromExternSheetIndex(int externSheetIndex) {
+ return _iBook.getSheetIndexFromExternSheetIndex(externSheetIndex);
+}
public HSSFWorkbook getWorkbook() {
return _uBook;
diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java b/src/java/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java index 9003c1b3bc..d7a3207383 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java @@ -19,6 +19,7 @@ package org.apache.poi.hssf.usermodel; import java.util.Iterator;
+import org.apache.poi.hssf.record.formula.eval.BlankEval;
import org.apache.poi.hssf.record.formula.eval.BoolEval;
import org.apache.poi.hssf.record.formula.eval.ErrorEval;
import org.apache.poi.hssf.record.formula.eval.NumberEval;
@@ -53,14 +54,7 @@ public class HSSFFormulaEvaluator /* almost implements FormulaEvaluator */ { }
}
public HSSFFormulaEvaluator(HSSFWorkbook workbook) {
- _bookEvaluator = new WorkbookEvaluator(HSSFEvaluationWorkbook.create(workbook));
- }
-
- /**
- * TODO for debug/test use
- */
- /* package */ int getEvaluationCount() {
- return _bookEvaluator.getEvaluationCount();
+ _bookEvaluator = new WorkbookEvaluator(HSSFEvaluationWorkbook.create(workbook));
}
/**
@@ -84,12 +78,23 @@ public class HSSFFormulaEvaluator /* almost implements FormulaEvaluator */ { _bookEvaluator.clearAllCachedResultValues();
}
/**
+ * Sets the cached value for a plain (non-formula) cell.
* Should be called whenever there are changes to individual input cells in the evaluated workbook.
* Failure to call this method after changing cell values will cause incorrect behaviour
* of the evaluate~ methods of this class
+ * @param never <code>null</code>. Use {@link BlankEval#INSTANCE} when the cell is being
+ * cleared. Otherwise an instance of {@link NumberEval}, {@link StringEval}, {@link BoolEval}
+ * or {@link ErrorEval} to represent a plain cell value.
*/
- public void clearCachedResultValue(Sheet sheet, int rowIndex, int columnIndex) {
- _bookEvaluator.clearCachedResultValue(sheet, rowIndex, columnIndex);
+ public void setCachedPlainValue(Sheet sheet, int rowIndex, int columnIndex, ValueEval value) {
+ _bookEvaluator.setCachedPlainValue(sheet, rowIndex, columnIndex, value);
+ }
+ /**
+ * Should be called to tell the cell value cache that the specified cell has just become a
+ * formula cell, or the formula text has changed
+ */
+ public void notifySetFormula(HSSFSheet sheet, int rowIndex, int columnIndex) {
+ _bookEvaluator.notifySetFormula(sheet, rowIndex, columnIndex);
}
/**
@@ -98,7 +103,9 @@ public class HSSFFormulaEvaluator /* almost implements FormulaEvaluator */ { * the cell and also its cell type. This method should be preferred over
* evaluateInCell() when the call should not modify the contents of the
* original cell.
- * @param cell
+ *
+ * @param cell may be <code>null</code> signifying that the cell is not present (or blank)
+ * @return <code>null</code> if the supplied cell is <code>null</code> or blank
*/
public CellValue evaluate(Cell cell) {
if (cell == null) {
@@ -116,6 +123,8 @@ public class HSSFFormulaEvaluator /* almost implements FormulaEvaluator */ { return new CellValue(cell.getNumericCellValue());
case HSSFCell.CELL_TYPE_STRING:
return new CellValue(cell.getRichStringCellValue().getString());
+ case HSSFCell.CELL_TYPE_BLANK:
+ return null;
}
throw new IllegalStateException("Bad cell type (" + cell.getCellType() + ")");
}
|