aboutsummaryrefslogtreecommitdiffstats
path: root/src/ooxml
diff options
context:
space:
mode:
authorJosh Micich <josh@apache.org>2008-09-19 07:32:34 +0000
committerJosh Micich <josh@apache.org>2008-09-19 07:32:34 +0000
commit02b99aeeddaa8208324e4703feb7fec1f9f6e75a (patch)
tree21899a492458cd080a3ad6f59c241bdadbcd2854 /src/ooxml
parente78a288ddfc77af316d6be4b7eaa535ba08badd4 (diff)
downloadpoi-02b99aeeddaa8208324e4703feb7fec1f9f6e75a.tar.gz
poi-02b99aeeddaa8208324e4703feb7fec1f9f6e75a.zip
Merged revisions 696860,696898 via svnmerge from
https://svn.apache.org/repos/asf/poi/trunk Quite a lot of manual fixing required. Also moved CellValue to top level class. ........ r696860 | josh | 2008-09-18 17:02:21 -0700 (Thu, 18 Sep 2008) | 1 line code clean-up (removed compiler warnings/unused methods) ........ r696898 | josh | 2008-09-18 19:19:58 -0700 (Thu, 18 Sep 2008) | 1 line Partitioning common formula logic. Introduced FormulaParsingWorkbook and EvaluationWorkbook interfaces to make merge with ooxml branch easier ........ git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@696961 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/ooxml')
-rw-r--r--src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Workbook.java27
-rw-r--r--src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationWorkbook.java167
-rw-r--r--src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFormulaEvaluator.java256
-rw-r--r--src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFName.java2
-rw-r--r--src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java39
-rw-r--r--src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestFormulaEvaluatorOnXSSF.java10
-rw-r--r--src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFormulaEvaluation.java15
7 files changed, 436 insertions, 80 deletions
diff --git a/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Workbook.java b/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Workbook.java
index bcf1b4ee96..40c5006874 100644
--- a/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Workbook.java
+++ b/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Workbook.java
@@ -122,15 +122,6 @@ public interface Workbook {
int getSheetIndex(Sheet sheet);
/**
- * Returns the external sheet index of the sheet
- * with the given internal index, creating one
- * if needed.
- * Used by some of the more obscure formula and
- * named range things.
- */
- int getExternalSheetIndex(int internalSheetIndex);
-
- /**
* create an HSSFSheet for this HSSFWorkbook, adds it to the sheets and returns
* the high level representation. Use this to create new sheets.
*
@@ -165,14 +156,6 @@ public interface Workbook {
int getNumberOfSheets();
/**
- * Finds the sheet index for a particular external sheet number.
- * @param externSheetNumber The external sheet number to convert
- * @return The index to the sheet found.
- */
- int getSheetIndexFromExternSheetIndex(int externSheetNumber);
-
-
- /**
* Get the HSSFSheet object at the given index.
* @param index of the sheet number (0-based physical & logical)
* @return HSSFSheet at the provided index
@@ -194,8 +177,6 @@ public interface Workbook {
*/
void removeSheetAt(int index);
-
- String findSheetNameFromExternSheet(int externSheetIndex);
/**
* determine whether the Excel GUI will backup the workbook when saving.
@@ -334,14 +315,6 @@ public interface Workbook {
String getNameName(int index);
/**
- * TODO - make this less cryptic / move elsewhere
- * @param refIndex Index to REF entry in EXTERNSHEET record in the Link Table
- * @param definedNameIndex zero-based to DEFINEDNAME or EXTERNALNAME record
- * @return the string representation of the defined or external name
- */
- String resolveNameXText(int refIndex, int definedNameIndex);
-
- /**
* Sets the printarea for the sheet provided
* <p>
* i.e. Reference = $A$1:$B$2
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationWorkbook.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationWorkbook.java
new file mode 100644
index 0000000000..2d442e8f4a
--- /dev/null
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationWorkbook.java
@@ -0,0 +1,167 @@
+package org.apache.poi.xssf.usermodel;
+
+import org.apache.poi.hssf.record.formula.NamePtg;
+import org.apache.poi.hssf.record.formula.NameXPtg;
+import org.apache.poi.hssf.record.formula.Ptg;
+import org.apache.poi.ss.formula.EvaluationName;
+import org.apache.poi.ss.formula.EvaluationWorkbook;
+import org.apache.poi.ss.formula.FormulaParser;
+import org.apache.poi.ss.formula.FormulaParsingWorkbook;
+import org.apache.poi.ss.formula.FormulaRenderingWorkbook;
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDefinedName;
+
+/**
+ * Internal POI use only
+ *
+ * @author Josh Micich
+ */
+public final class XSSFEvaluationWorkbook implements FormulaRenderingWorkbook, EvaluationWorkbook, FormulaParsingWorkbook {
+
+ private final XSSFWorkbook _uBook;
+
+ public static XSSFEvaluationWorkbook create(XSSFWorkbook book) {
+ if (book == null) {
+ return null;
+ }
+ return new XSSFEvaluationWorkbook(book);
+ }
+
+ private XSSFEvaluationWorkbook(XSSFWorkbook book) {
+ _uBook = book;
+ }
+
+ private int convertFromExternalSheetIndex(int externSheetIndex) {
+ return externSheetIndex;
+ }
+ /**
+ * @returns the external sheet index of the sheet with the given internal
+ * index, creating one if needed. Used by some of the more obscure
+ * formula and named range things. Fairly easy on XSSF (we
+ * think...) since the internal and external indicies are the same
+ */
+ private int convertToExternalSheetIndex(int sheetIndex) {
+ return sheetIndex;
+ }
+
+ public int getExternalSheetIndex(String sheetName) {
+ int sheetIndex = _uBook.getSheetIndex(sheetName);
+ return convertToExternalSheetIndex(sheetIndex);
+ }
+
+ public EvaluationName getName(int index) {
+ return new Name(_uBook.getNameAt(index), index, this);
+ }
+
+ public EvaluationName getName(String name) {
+ for(int i=0; i < _uBook.getNumberOfNames(); i++) {
+ String nameText = _uBook.getNameName(i);
+ if (name.equalsIgnoreCase(nameText)) {
+ return new Name(_uBook.getNameAt(i), i, this);
+ }
+ }
+ return null;
+ }
+
+ public int getSheetIndex(Sheet sheet) {
+ return _uBook.getSheetIndex(sheet);
+ }
+
+ public String getSheetName(int sheetIndex) {
+ return _uBook.getSheetName(sheetIndex);
+ }
+
+ public int getNameIndex(String name) {
+ return _uBook.getNameIndex(name);
+ }
+
+ public NameXPtg getNameXPtg(String name) {
+ // may require to return null to make tests pass
+ throw new RuntimeException("Not implemented yet");
+ }
+
+ public Sheet getSheet(int sheetIndex) {
+ return _uBook.getSheetAt(sheetIndex);
+ }
+
+ /**
+ * Doesn't do anything - returns the same index
+ * TODO - figure out if this is a ole2 specific thing, or
+ * if we need to do something proper here too!
+ */
+ public Sheet getSheetByExternSheetIndex(int externSheetIndex) {
+ int sheetIndex = convertFromExternalSheetIndex(externSheetIndex);
+ return _uBook.getSheetAt(sheetIndex);
+ }
+
+ public Workbook getWorkbook() {
+ return _uBook;
+ }
+
+ /**
+ * TODO - figure out what the hell this methods does in
+ * HSSF...
+ */
+ public String resolveNameXText(NameXPtg n) {
+ throw new RuntimeException("method not implemented yet");
+ }
+
+ public String getSheetNameByExternSheet(int externSheetIndex) {
+ int sheetIndex = convertFromExternalSheetIndex(externSheetIndex);
+ return _uBook.getSheetName(sheetIndex);
+ }
+
+ public String getNameText(NamePtg namePtg) {
+ return _uBook.getNameAt(namePtg.getIndex()).getNameName();
+ }
+ public EvaluationName getName(NamePtg namePtg) {
+ int ix = namePtg.getIndex();
+ return new Name(_uBook.getNameAt(ix), ix, this);
+ }
+ public Ptg[] getFormulaTokens(Cell cell) {
+ XSSFEvaluationWorkbook frBook = XSSFEvaluationWorkbook.create(_uBook);
+ return FormulaParser.parse(cell.getCellFormula(), frBook);
+ }
+
+ private static final class Name implements EvaluationName {
+
+ private final XSSFName _nameRecord;
+ private final int _index;
+ private final FormulaParsingWorkbook _fpBook;
+
+ public Name(XSSFName name, int index, FormulaParsingWorkbook fpBook) {
+ _nameRecord = name;
+ _index = index;
+ _fpBook = fpBook;
+ }
+
+ public Ptg[] getNameDefinition() {
+
+ return FormulaParser.parse(_nameRecord.getReference(), _fpBook);
+ }
+
+ public String getNameText() {
+ return _nameRecord.getNameName();
+ }
+
+ public boolean hasFormula() {
+ // TODO - no idea if this is right
+ CTDefinedName ctn = _nameRecord.getCTName();
+ String strVal = ctn.getStringValue();
+ return !ctn.getFunction() && strVal != null && strVal.length() > 0;
+ }
+
+ public boolean isFunctionName() {
+ return _nameRecord.isFunctionName();
+ }
+
+ public boolean isRange() {
+ return hasFormula(); // TODO - is this right?
+ }
+ public NamePtg createPtg() {
+ return new NamePtg(_index);
+ }
+ }
+}
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFormulaEvaluator.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFormulaEvaluator.java
new file mode 100644
index 0000000000..3dcedf8f5e
--- /dev/null
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFormulaEvaluator.java
@@ -0,0 +1,256 @@
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.xssf.usermodel;
+
+import java.util.Iterator;
+
+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;
+import org.apache.poi.hssf.record.formula.eval.StringEval;
+import org.apache.poi.hssf.record.formula.eval.ValueEval;
+import org.apache.poi.hssf.usermodel.HSSFCell;
+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;
+
+/**
+ * Evaluates formula cells.<p/>
+ *
+ * For performance reasons, this class keeps a cache of all previously calculated intermediate
+ * cell values. Be sure to call {@link #clearCache()} if any workbook cells are changed between
+ * calls to evaluate~ methods on this class.
+ *
+ * @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;
+ * @author Josh Micich
+ */
+public class XSSFFormulaEvaluator implements FormulaEvaluator {
+
+ private WorkbookEvaluator _bookEvaluator;
+
+ public XSSFFormulaEvaluator(XSSFWorkbook workbook) {
+ _bookEvaluator = new WorkbookEvaluator(XSSFEvaluationWorkbook.create(workbook));
+ }
+
+ /**
+ * TODO for debug/test use
+ */
+ /* package */ int getEvaluationCount() {
+ return _bookEvaluator.getEvaluationCount();
+ }
+
+
+ /**
+ * Should be called whenever there are major changes (e.g. moving sheets) to 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
+ */
+ public void clearAllCachedResultValues() {
+ _bookEvaluator.clearAllCachedResultValues();
+ }
+ /**
+ * 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
+ */
+ public void clearCachedResultValue(Sheet sheet, int rowIndex, int columnIndex) {
+ _bookEvaluator.clearCachedResultValue(sheet, rowIndex, columnIndex);
+ }
+
+ /**
+ * If cell contains a formula, the formula is evaluated and returned,
+ * else the CellValue simply copies the appropriate cell value from
+ * 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
+ */
+ public CellValue evaluate(Cell cell) {
+ if (cell == null) {
+ return null;
+ }
+
+ switch (cell.getCellType()) {
+ case XSSFCell.CELL_TYPE_BOOLEAN:
+ return CellValue.valueOf(cell.getBooleanCellValue());
+ case XSSFCell.CELL_TYPE_ERROR:
+ return CellValue.getError(cell.getErrorCellValue());
+ case XSSFCell.CELL_TYPE_FORMULA:
+ return evaluateFormulaCellValue(cell);
+ case XSSFCell.CELL_TYPE_NUMERIC:
+ return new CellValue(cell.getNumericCellValue());
+ case XSSFCell.CELL_TYPE_STRING:
+ return new CellValue(cell.getRichStringCellValue().getString());
+ }
+ throw new IllegalStateException("Bad cell type (" + cell.getCellType() + ")");
+ }
+
+
+ /**
+ * If cell contains formula, it evaluates the formula,
+ * and saves the result of the formula. The cell
+ * remains as a formula cell.
+ * Else if cell does not contain formula, this method leaves
+ * the cell unchanged.
+ * Note that the type of the formula result is returned,
+ * so you know what kind of value is also stored with
+ * the formula.
+ * <pre>
+ * int evaluatedCellType = evaluator.evaluateFormulaCell(cell);
+ * </pre>
+ * Be aware that your cell will hold both the formula,
+ * and the result. If you want the cell replaced with
+ * the result of the formula, use {@link #evaluateInCell(HSSFCell)}
+ * @param cell The cell to evaluate
+ * @return The type of the formula result (the cell's type remains as HSSFCell.CELL_TYPE_FORMULA however)
+ */
+ public int evaluateFormulaCell(Cell cell) {
+ if (cell == null || cell.getCellType() != XSSFCell.CELL_TYPE_FORMULA) {
+ return -1;
+ }
+ CellValue cv = evaluateFormulaCellValue(cell);
+ // cell remains a formula cell, but the cached value is changed
+ setCellValue(cell, cv);
+ return cv.getCellType();
+ }
+
+ /**
+ * If cell contains formula, it evaluates the formula, and
+ * puts the formula result back into the cell, in place
+ * of the old formula.
+ * Else if cell does not contain formula, this method leaves
+ * the cell unchanged.
+ * Note that the same instance of HSSFCell is returned to
+ * allow chained calls like:
+ * <pre>
+ * int evaluatedCellType = evaluator.evaluateInCell(cell).getCellType();
+ * </pre>
+ * Be aware that your cell value will be changed to hold the
+ * result of the formula. If you simply want the formula
+ * value computed for you, use {@link #evaluateFormulaCell(HSSFCell)}
+ * @param cell
+ */
+ public XSSFCell evaluateInCell(Cell cell) {
+ if (cell == null) {
+ return null;
+ }
+ XSSFCell result = (XSSFCell) cell;
+ if (cell.getCellType() == XSSFCell.CELL_TYPE_FORMULA) {
+ CellValue cv = evaluateFormulaCellValue(cell);
+ setCellType(cell, cv); // cell will no longer be a formula cell
+ setCellValue(cell, cv);
+ }
+ return result;
+ }
+ private static void setCellType(Cell cell, CellValue cv) {
+ int cellType = cv.getCellType();
+ switch (cellType) {
+ case XSSFCell.CELL_TYPE_BOOLEAN:
+ case XSSFCell.CELL_TYPE_ERROR:
+ case XSSFCell.CELL_TYPE_NUMERIC:
+ case XSSFCell.CELL_TYPE_STRING:
+ cell.setCellType(cellType);
+ return;
+ case XSSFCell.CELL_TYPE_BLANK:
+ // never happens - blanks eventually get translated to zero
+ case XSSFCell.CELL_TYPE_FORMULA:
+ // this will never happen, we have already evaluated the formula
+ }
+ throw new IllegalStateException("Unexpected cell value type (" + cellType + ")");
+ }
+
+ private static void setCellValue(Cell cell, CellValue cv) {
+ int cellType = cv.getCellType();
+ switch (cellType) {
+ case XSSFCell.CELL_TYPE_BOOLEAN:
+ cell.setCellValue(cv.getBooleanValue());
+ break;
+ case XSSFCell.CELL_TYPE_ERROR:
+ cell.setCellErrorValue(cv.getErrorValue());
+ break;
+ case XSSFCell.CELL_TYPE_NUMERIC:
+ cell.setCellValue(cv.getNumberValue());
+ break;
+ case XSSFCell.CELL_TYPE_STRING:
+ cell.setCellValue(new XSSFRichTextString(cv.getStringValue()));
+ break;
+ case XSSFCell.CELL_TYPE_BLANK:
+ // never happens - blanks eventually get translated to zero
+ case XSSFCell.CELL_TYPE_FORMULA:
+ // this will never happen, we have already evaluated the formula
+ default:
+ throw new IllegalStateException("Unexpected cell value type (" + cellType + ")");
+ }
+ }
+
+ /**
+ * 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 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);
+ }
+ }
+ }
+ }
+
+ /**
+ * Returns a CellValue wrapper around the supplied ValueEval instance.
+ * @param eval
+ */
+ private CellValue evaluateFormulaCellValue(Cell cell) {
+ ValueEval eval = _bookEvaluator.evaluate(cell);
+ if (eval instanceof NumberEval) {
+ NumberEval ne = (NumberEval) eval;
+ return new CellValue(ne.getNumberValue());
+ }
+ if (eval instanceof BoolEval) {
+ BoolEval be = (BoolEval) eval;
+ return CellValue.valueOf(be.getBooleanValue());
+ }
+ if (eval instanceof StringEval) {
+ StringEval ne = (StringEval) eval;
+ return new CellValue(ne.getStringValue());
+ }
+ if (eval instanceof ErrorEval) {
+ return CellValue.getError(((ErrorEval)eval).getErrorCode());
+ }
+ throw new RuntimeException("Unexpected eval class (" + eval.getClass().getName() + ")");
+ }
+}
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFName.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFName.java
index 5d6b7aec0c..0e9e573b45 100644
--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFName.java
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFName.java
@@ -37,7 +37,7 @@ public class XSSFName implements Name {
public boolean isFunctionName() {
// TODO Figure out how HSSF does this, and do the same!
- return false;
+ return ctName.getFunction(); // maybe this works - verify
}
/**
* Returns the underlying named range object
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
index 5bc8c14e5d..a7b30ff191 100644
--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
@@ -408,15 +408,6 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook {
return -1;
}
- /**
- * TODO - figure out what the hell this methods does in
- * HSSF...
- */
- public String resolveNameXText(int refIndex, int definedNameIndex) {
- // TODO Replace with something proper
- return null;
- }
-
public short getNumCellStyles() {
return (short) ((StylesTable)stylesSource).getNumCellStyles();
}
@@ -450,23 +441,6 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook {
return -1;
}
- /**
- * Doesn't do anything - returns the same index
- * TODO - figure out if this is a ole2 specific thing, or
- * if we need to do something proper here too!
- */
- public int getSheetIndexFromExternSheetIndex(int externSheetNumber) {
- return externSheetNumber;
- }
- /**
- * Doesn't do anything special - returns the same as getSheetName()
- * TODO - figure out if this is a ole2 specific thing, or
- * if we need to do something proper here too!
- */
- public String findSheetNameFromExternSheet(int externSheetIndex) {
- return getSheetName(externSheetIndex);
- }
-
public Sheet getSheet(String name) {
CTSheet[] sheets = this.workbook.getSheets().getSheetArray();
for (int i = 0 ; i < sheets.length ; ++i) {
@@ -495,19 +469,6 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook {
return this.sheets.indexOf(sheet);
}
- /**
- * Returns the external sheet index of the sheet
- * with the given internal index, creating one
- * if needed.
- * Used by some of the more obscure formula and
- * named range things.
- * Fairly easy on XSSF (we think...) since the
- * internal and external indicies are the same
- */
- public int getExternalSheetIndex(int internalSheetIndex) {
- return internalSheetIndex;
- }
-
public String getSheetName(int sheet) {
return this.workbook.getSheets().getSheetArray(sheet).getName();
}
diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestFormulaEvaluatorOnXSSF.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestFormulaEvaluatorOnXSSF.java
index 90c75c5a07..9464c05b8f 100644
--- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestFormulaEvaluatorOnXSSF.java
+++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestFormulaEvaluatorOnXSSF.java
@@ -28,10 +28,10 @@ import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.hssf.record.formula.eval.TestFormulasFromSpreadsheet;
import org.apache.poi.hssf.record.formula.functions.TestMathX;
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;
import org.openxml4j.opc.Package;
/**
@@ -90,7 +90,7 @@ public final class TestFormulaEvaluatorOnXSSF extends TestCase {
public static final int NUMBER_OF_ROWS_PER_FUNCTION = 4;
}
- private Workbook workbook;
+ private XSSFWorkbook workbook;
private Sheet sheet;
// Note - multiple failures are aggregated before ending.
// If one or more functions fail, a single AssertionFailedError is thrown at the end
@@ -107,7 +107,7 @@ public final class TestFormulaEvaluatorOnXSSF extends TestCase {
}
- private static void confirmExpectedResult(String msg, Cell expected, FormulaEvaluator.CellValue actual) {
+ private static void confirmExpectedResult(String msg, Cell expected, CellValue actual) {
if (expected == null) {
throw new AssertionFailedError(msg + " - Bad setup data expected value is null");
}
@@ -199,7 +199,7 @@ public final class TestFormulaEvaluatorOnXSSF extends TestCase {
*/
private void processFunctionGroup(int startRowIndex, String testFocusFunctionName) {
- FormulaEvaluator evaluator = new FormulaEvaluator(workbook);
+ FormulaEvaluator evaluator = new XSSFFormulaEvaluator(workbook);
int rowIndex = startRowIndex;
while (true) {
@@ -256,7 +256,7 @@ public final class TestFormulaEvaluatorOnXSSF extends TestCase {
continue;
}
- FormulaEvaluator.CellValue actualValue;
+ CellValue actualValue;
try {
actualValue = evaluator.evaluate(c);
} catch (RuntimeException e) {
diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFormulaEvaluation.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFormulaEvaluation.java
index 70a54b5ef9..160f5609bc 100644
--- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFormulaEvaluation.java
+++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFormulaEvaluation.java
@@ -17,15 +17,14 @@
package org.apache.poi.xssf.usermodel;
+import junit.framework.TestCase;
+
import org.apache.poi.ss.usermodel.Cell;
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;
-
-import junit.framework.TestCase;
-public class TestXSSFFormulaEvaluation extends TestCase {
+public final class TestXSSFFormulaEvaluation extends TestCase {
public TestXSSFFormulaEvaluation(String name) {
super(name);
@@ -37,7 +36,7 @@ public class TestXSSFFormulaEvaluation extends TestCase {
}
public void testSimpleArithmatic() {
- Workbook wb = new XSSFWorkbook();
+ XSSFWorkbook wb = new XSSFWorkbook();
Sheet s = wb.createSheet();
Row r = s.createRow(0);
@@ -49,7 +48,7 @@ public class TestXSSFFormulaEvaluation extends TestCase {
c2.setCellFormula("10/2");
assertTrue( Double.isNaN(c2.getNumericCellValue()) );
- FormulaEvaluator fe = new FormulaEvaluator(s, wb);
+ FormulaEvaluator fe = new XSSFFormulaEvaluator(wb);
fe.evaluateFormulaCell(c1);
fe.evaluateFormulaCell(c2);
@@ -59,7 +58,7 @@ public class TestXSSFFormulaEvaluation extends TestCase {
}
public void testSumCount() {
- Workbook wb = new XSSFWorkbook();
+ XSSFWorkbook wb = new XSSFWorkbook();
Sheet s = wb.createSheet();
Row r = s.createRow(0);
r.createCell(0).setCellValue(2.5);
@@ -87,7 +86,7 @@ public class TestXSSFFormulaEvaluation extends TestCase {
// Evaluate and test
- FormulaEvaluator fe = new FormulaEvaluator(s, wb);
+ FormulaEvaluator fe = new XSSFFormulaEvaluator(wb);
fe.evaluateFormulaCell(c1);
fe.evaluateFormulaCell(c2);