bug 59791: FormulaEvaluator#evaluateFormulaCell(Cell) should return an integer for backwards compatibility

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1751261 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Javen O'Neal 2016-07-04 12:21:42 +00:00
parent 034d3cfcca
commit 268c5deeb2
30 changed files with 195 additions and 103 deletions

View File

@ -36,6 +36,7 @@ import org.apache.poi.ss.usermodel.FormulaEvaluator;
import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.util.Internal;
/** /**
* Evaluates formula cells.<p/> * Evaluates formula cells.<p/>
@ -213,15 +214,37 @@ public class HSSFFormulaEvaluator implements FormulaEvaluator, WorkbookEvaluator
* @return -1 for non-formula cells, or the type of the <em>formula result</em> * @return -1 for non-formula cells, or the type of the <em>formula result</em>
*/ */
@Override @Override
public CellType evaluateFormulaCell(Cell cell) { public int evaluateFormulaCell(Cell cell) {
if (cell == null || cell.getCellTypeEnum() != CellType.FORMULA) { return evaluateFormulaCellEnum(cell).getCode();
return CellType._UNINITIALIZED;
}
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 saves the result of the formula. The
* cell remains as a formula cell. If the cell does not contain formula, this method returns -1
* and leaves the cell unchanged.
*
* Note that the type of the <em>formula result</em> is returned, so you know what kind of
* cached formula result 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(org.apache.poi.ss.usermodel.Cell)}
* @param cell The cell to evaluate
* @return -1 for non-formula cells, or the type of the <em>formula result</em>
* @deprecated POI 3.15 beta 3
*/
@Internal
@Override
public CellType evaluateFormulaCellEnum(Cell cell) {
if (cell == null || cell.getCellTypeEnum() != CellType.FORMULA) {
return CellType._UNINITIALIZED;
}
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 * If cell contains formula, it evaluates the formula, and
@ -236,7 +259,7 @@ public class HSSFFormulaEvaluator implements FormulaEvaluator, WorkbookEvaluator
* </pre> * </pre>
* Be aware that your cell value will be changed to hold the * Be aware that your cell value will be changed to hold the
* result of the formula. If you simply want the formula * result of the formula. If you simply want the formula
* value computed for you, use {@link #evaluateFormulaCell(Cell)}} * value computed for you, use {@link #evaluateFormulaCellEnum(Cell)}}
*/ */
@Override @Override
public HSSFCell evaluateInCell(Cell cell) { public HSSFCell evaluateInCell(Cell cell) {
@ -331,7 +354,7 @@ public class HSSFFormulaEvaluator implements FormulaEvaluator, WorkbookEvaluator
for(Row r : sheet) { for(Row r : sheet) {
for (Cell c : r) { for (Cell c : r) {
if (c.getCellTypeEnum() == CellType.FORMULA) { if (c.getCellTypeEnum() == CellType.FORMULA) {
evaluator.evaluateFormulaCell(c); evaluator.evaluateFormulaCellEnum(c);
} }
} }
} }

View File

@ -47,7 +47,7 @@ package org.apache.poi.ss.formula;
* <li>To retain freedom to change any cell definition at any time, an application may classify all * <li>To retain freedom to change any cell definition at any time, an application may classify all
* cells as 'not final'. This freedom comes at the expense of greater memory consumption.</li> * cells as 'not final'. This freedom comes at the expense of greater memory consumption.</li>
* <li>For the purpose of these classifications, setting the cached formula result of a cell (for * <li>For the purpose of these classifications, setting the cached formula result of a cell (for
* example in {@link org.apache.poi.ss.usermodel.FormulaEvaluator#evaluateFormulaCell(org.apache.poi.ss.usermodel.Cell)}) * example in {@link org.apache.poi.ss.usermodel.FormulaEvaluator#evaluateFormulaCellEnum(org.apache.poi.ss.usermodel.Cell)})
* does not constitute changing the definition of the cell.</li> * does not constitute changing the definition of the cell.</li>
* <li>Updating cells which have been classified as 'final' will cause the evaluator to behave * <li>Updating cells which have been classified as 'final' will cause the evaluator to behave
* unpredictably (typically ignoring the update).</li> * unpredictably (typically ignoring the update).</li>

View File

@ -884,7 +884,7 @@ public class DataFormatter implements Observer {
if (evaluator == null) { if (evaluator == null) {
return cell.getCellFormula(); return cell.getCellFormula();
} }
cellType = evaluator.evaluateFormulaCell(cell); cellType = evaluator.evaluateFormulaCellEnum(cell);
} }
switch (cellType) { switch (cellType) {
case NUMERIC : case NUMERIC :

View File

@ -19,6 +19,8 @@ package org.apache.poi.ss.usermodel;
import java.util.Map; import java.util.Map;
import org.apache.poi.util.Internal;
/** /**
* Evaluates formula cells.<p/> * Evaluates formula cells.<p/>
* *
@ -96,10 +98,36 @@ public interface FormulaEvaluator {
* the result of the formula, use {@link #evaluateInCell(Cell)} * the result of the formula, use {@link #evaluateInCell(Cell)}
* @param cell The cell to evaluate * @param cell The cell to evaluate
* @return The type of the formula result, i.e. -1 if the cell is not a formula, * @return The type of the formula result, i.e. -1 if the cell is not a formula,
* or one of CellType.NUMERIC, CellType.STRING, CellType.BOOLEAN, CellType.ERROR * or one of {@link CellType#NUMERIC}, {@link CellType#STRING},
* {@link CellType#BOOLEAN}, {@link CellType#ERROR}
* Note: the cell's type remains as CellType.FORMULA however. * Note: the cell's type remains as CellType.FORMULA however.
*/ */
CellType evaluateFormulaCell(Cell cell); int evaluateFormulaCell(Cell cell);
/**
* 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>
* CellType evaluatedCellType = evaluator.evaluateFormulaCellEnum(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(Cell)}
* @param cell The cell to evaluate
* @return The type of the formula result, i.e. -1 if the cell is not a formula,
* or one of {@link CellType#NUMERIC}, {@link CellType#STRING},
* {@link CellType#BOOLEAN}, {@link CellType#ERROR}
* Note: the cell's type remains as CellType.FORMULA however.
* @deprecated POI 3.15 beta 3. Will be deleted when we make the CellType enum transition. See bug 59791.
*/
@Internal
CellType evaluateFormulaCellEnum(Cell cell);
/** /**
* If cell contains formula, it evaluates the formula, and * If cell contains formula, it evaluates the formula, and
@ -114,7 +142,7 @@ public interface FormulaEvaluator {
* </pre> * </pre>
* Be aware that your cell value will be changed to hold the * Be aware that your cell value will be changed to hold the
* result of the formula. If you simply want the formula * result of the formula. If you simply want the formula
* value computed for you, use {@link #evaluateFormulaCell(Cell)} * value computed for you, use {@link #evaluateFormulaCellEnum(Cell)}
* @param cell * @param cell
*/ */
Cell evaluateInCell(Cell cell); Cell evaluateInCell(Cell cell);

View File

@ -69,18 +69,34 @@ public class SheetUtil {
* See Bugzilla #50021 * See Bugzilla #50021
*/ */
private static final FormulaEvaluator dummyEvaluator = new FormulaEvaluator(){ private static final FormulaEvaluator dummyEvaluator = new FormulaEvaluator(){
@Override
public void clearAllCachedResultValues(){} public void clearAllCachedResultValues(){}
@Override
public void notifySetFormula(Cell cell) {} public void notifySetFormula(Cell cell) {}
@Override
public void notifyDeleteCell(Cell cell) {} public void notifyDeleteCell(Cell cell) {}
@Override
public void notifyUpdateCell(Cell cell) {} public void notifyUpdateCell(Cell cell) {}
@Override
public CellValue evaluate(Cell cell) {return null; } public CellValue evaluate(Cell cell) {return null; }
@Override
public Cell evaluateInCell(Cell cell) { return null; } public Cell evaluateInCell(Cell cell) { return null; }
@Override
public void setupReferencedWorkbooks(Map<String, FormulaEvaluator> workbooks) {} public void setupReferencedWorkbooks(Map<String, FormulaEvaluator> workbooks) {}
@Override
public void setDebugEvaluationOutputForNextEval(boolean value) {} public void setDebugEvaluationOutputForNextEval(boolean value) {}
@Override
public void setIgnoreMissingWorkbooks(boolean ignore) {} public void setIgnoreMissingWorkbooks(boolean ignore) {}
@Override
public void evaluateAll() {} public void evaluateAll() {}
public CellType evaluateFormulaCell(Cell cell) { @Override
public int evaluateFormulaCell(Cell cell) {
return cell.getCachedFormulaResultType();
}
/** @deprecated POI 3.15 beta 3. Will be deleted when we make the CellType enum transition. See bug 59791. */
@Internal
@Override
public CellType evaluateFormulaCellEnum(Cell cell) {
return cell.getCachedFormulaResultTypeEnum(); return cell.getCachedFormulaResultTypeEnum();
} }
}; };

View File

@ -85,7 +85,7 @@ public final class SXSSFFormulaEvaluator extends BaseXSSFFormulaEvaluator {
* </pre> * </pre>
* Be aware that your cell value will be changed to hold the * Be aware that your cell value will be changed to hold the
* result of the formula. If you simply want the formula * result of the formula. If you simply want the formula
* value computed for you, use {@link #evaluateFormulaCell(org.apache.poi.ss.usermodel.Cell)} } * value computed for you, use {@link #evaluateFormulaCellEnum(org.apache.poi.ss.usermodel.Cell)} }
*/ */
public SXSSFCell evaluateInCell(Cell cell) { public SXSSFCell evaluateInCell(Cell cell) {
doEvaluateInCell(cell); doEvaluateInCell(cell);
@ -122,7 +122,7 @@ public final class SXSSFFormulaEvaluator extends BaseXSSFFormulaEvaluator {
for (Row r : sheet) { for (Row r : sheet) {
for (Cell c : r) { for (Cell c : r) {
if (c.getCellTypeEnum() == CellType.FORMULA) { if (c.getCellTypeEnum() == CellType.FORMULA) {
eval.evaluateFormulaCell(c); eval.evaluateFormulaCellEnum(c);
} }
} }
} }

View File

@ -32,6 +32,7 @@ import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellType; import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.CellValue; import org.apache.poi.ss.usermodel.CellValue;
import org.apache.poi.ss.usermodel.FormulaEvaluator; import org.apache.poi.ss.usermodel.FormulaEvaluator;
import org.apache.poi.util.Internal;
/** /**
* Internal POI use only - parent of XSSF and SXSSF formula evaluators * Internal POI use only - parent of XSSF and SXSSF formula evaluators
@ -112,7 +113,31 @@ public abstract class BaseXSSFFormulaEvaluator implements FormulaEvaluator, Work
* @param cell The cell to evaluate * @param cell The cell to evaluate
* @return The type of the formula result (the cell's type remains as CellType.FORMULA however) * @return The type of the formula result (the cell's type remains as CellType.FORMULA however)
*/ */
public CellType evaluateFormulaCell(Cell cell) { public int evaluateFormulaCell(Cell cell) {
return evaluateFormulaCellEnum(cell).getCode();
}
/**
* 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 #evaluate(org.apache.poi.ss.usermodel.Cell)} }
* @param cell The cell to evaluate
* @return The type of the formula result (the cell's type remains as CellType.FORMULA however)
* @deprecated POI 3.15 beta 3. Will be deleted when we make the CellType enum transition. See bug 59791.
*/
@Internal
public CellType evaluateFormulaCellEnum(Cell cell) {
if (cell == null || cell.getCellTypeEnum() != CellType.FORMULA) { if (cell == null || cell.getCellTypeEnum() != CellType.FORMULA) {
return CellType._UNINITIALIZED; return CellType._UNINITIALIZED;
} }

View File

@ -68,7 +68,7 @@ public final class XSSFFormulaEvaluator extends BaseXSSFFormulaEvaluator {
* </pre> * </pre>
* Be aware that your cell value will be changed to hold the * Be aware that your cell value will be changed to hold the
* result of the formula. If you simply want the formula * result of the formula. If you simply want the formula
* value computed for you, use {@link #evaluateFormulaCell(org.apache.poi.ss.usermodel.Cell)} } * value computed for you, use {@link #evaluateFormulaCellEnum(org.apache.poi.ss.usermodel.Cell)} }
* @param cell * @param cell
*/ */
public XSSFCell evaluateInCell(Cell cell) { public XSSFCell evaluateInCell(Cell cell) {

View File

@ -106,7 +106,7 @@ public final class TestSXSSFFormulaEvaluation {
FormulaEvaluator eval = wb.getCreationHelper().createFormulaEvaluator(); FormulaEvaluator eval = wb.getCreationHelper().createFormulaEvaluator();
try { try {
eval.evaluateFormulaCell(c); eval.evaluateFormulaCellEnum(c);
fail("Evaluate shouldn't work, as reference outside the window"); fail("Evaluate shouldn't work, as reference outside the window");
} catch(SXSSFFormulaEvaluator.RowFlushedException e) { } catch(SXSSFFormulaEvaluator.RowFlushedException e) {
// Expected // Expected
@ -152,7 +152,7 @@ public final class TestSXSSFFormulaEvaluation {
c.setCellFormula("A1*2"); c.setCellFormula("A1*2");
assertEquals(0, (int)c.getNumericCellValue()); assertEquals(0, (int)c.getNumericCellValue());
eval.evaluateFormulaCell(c); eval.evaluateFormulaCellEnum(c);
assertEquals(3, (int)c.getNumericCellValue()); assertEquals(3, (int)c.getNumericCellValue());
wb.close(); wb.close();
@ -168,12 +168,12 @@ public final class TestSXSSFFormulaEvaluation {
SXSSFCell c = s.createRow(0).createCell(0); SXSSFCell c = s.createRow(0).createCell(0);
c.setCellFormula("1+2"); c.setCellFormula("1+2");
assertEquals(0, (int)c.getNumericCellValue()); assertEquals(0, (int)c.getNumericCellValue());
eval.evaluateFormulaCell(c); eval.evaluateFormulaCellEnum(c);
assertEquals(3, (int)c.getNumericCellValue()); assertEquals(3, (int)c.getNumericCellValue());
c = s.createRow(1).createCell(0); c = s.createRow(1).createCell(0);
c.setCellFormula("CONCATENATE(\"hello\",\" \",\"world\")"); c.setCellFormula("CONCATENATE(\"hello\",\" \",\"world\")");
eval.evaluateFormulaCell(c); eval.evaluateFormulaCellEnum(c);
assertEquals("hello world", c.getStringCellValue()); assertEquals("hello world", c.getStringCellValue());
wb.close(); wb.close();

View File

@ -663,14 +663,14 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
assertEquals(3.0, c.getNumericCellValue(), 0); assertEquals(3.0, c.getNumericCellValue(), 0);
FormulaEvaluator formulaEvaluator = wb.getCreationHelper().createFormulaEvaluator(); FormulaEvaluator formulaEvaluator = wb.getCreationHelper().createFormulaEvaluator();
formulaEvaluator.evaluateFormulaCell(c); formulaEvaluator.evaluateFormulaCellEnum(c);
assertEquals("SUM(\n1,2\n)", c.getCellFormula()); assertEquals("SUM(\n1,2\n)", c.getCellFormula());
assertEquals(3.0, c.getNumericCellValue(), 0); assertEquals(3.0, c.getNumericCellValue(), 0);
// For 51875 // For 51875
Cell b3 = s.getRow(2).getCell(1); Cell b3 = s.getRow(2).getCell(1);
formulaEvaluator.evaluateFormulaCell(b3); formulaEvaluator.evaluateFormulaCellEnum(b3);
assertEquals("B1+B2", b3.getCellFormula()); // The newline is lost for shared formulas assertEquals("B1+B2", b3.getCellFormula()); // The newline is lost for shared formulas
assertEquals(3.0, b3.getNumericCellValue(), 0); assertEquals(3.0, b3.getNumericCellValue(), 0);
@ -1375,8 +1375,8 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
// Try evaluating both // Try evaluating both
XSSFFormulaEvaluator eval = new XSSFFormulaEvaluator(wb); XSSFFormulaEvaluator eval = new XSSFFormulaEvaluator(wb);
eval.evaluateFormulaCell(c1); eval.evaluateFormulaCellEnum(c1);
eval.evaluateFormulaCell(c2); eval.evaluateFormulaCellEnum(c2);
assertEquals(20.0, c1.getNumericCellValue(), 0); assertEquals(20.0, c1.getNumericCellValue(), 0);
assertEquals(20.0, c2.getNumericCellValue(), 0); assertEquals(20.0, c2.getNumericCellValue(), 0);
@ -2959,7 +2959,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
cell = row.getCell(1); cell = row.getCell(1);
assertEquals(CellType.BLANK, cell.getCellTypeEnum()); assertEquals(CellType.BLANK, cell.getCellTypeEnum());
assertEquals(CellType._UNINITIALIZED, evaluator.evaluateFormulaCell(cell)); assertEquals(CellType._UNINITIALIZED, evaluator.evaluateFormulaCellEnum(cell));
// A3 // A3
row = worksheet.getRow(2); row = worksheet.getRow(2);
@ -2967,7 +2967,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
assertEquals(CellType.FORMULA, cell.getCellTypeEnum()); assertEquals(CellType.FORMULA, cell.getCellTypeEnum());
assertEquals("IF(ISBLANK(B3),\"\",B3)", cell.getCellFormula()); assertEquals("IF(ISBLANK(B3),\"\",B3)", cell.getCellFormula());
assertEquals(CellType.STRING, evaluator.evaluateFormulaCell(cell)); assertEquals(CellType.STRING, evaluator.evaluateFormulaCellEnum(cell));
CellValue value = evaluator.evaluate(cell); CellValue value = evaluator.evaluate(cell);
assertEquals("", value.getStringValue()); assertEquals("", value.getStringValue());
@ -2977,7 +2977,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
assertEquals(CellType.FORMULA, cell.getCellTypeEnum()); assertEquals(CellType.FORMULA, cell.getCellTypeEnum());
assertEquals("COUNTBLANK(A1:A4)", cell.getCellFormula()); assertEquals("COUNTBLANK(A1:A4)", cell.getCellFormula());
assertEquals(CellType.NUMERIC, evaluator.evaluateFormulaCell(cell)); assertEquals(CellType.NUMERIC, evaluator.evaluateFormulaCellEnum(cell));
value = evaluator.evaluate(cell); value = evaluator.evaluate(cell);
assertEquals(1.0, value.getNumberValue(), 0.1); assertEquals(1.0, value.getNumberValue(), 0.1);

View File

@ -488,7 +488,7 @@ public final class TestXSSFFormulaParser {
for (Cell cell : row) { for (Cell cell : row) {
if (cell.getCellTypeEnum() == CellType.FORMULA) { if (cell.getCellTypeEnum() == CellType.FORMULA) {
try { try {
evaluator.evaluateFormulaCell(cell); evaluator.evaluateFormulaCellEnum(cell);
} catch (Exception e) { } catch (Exception e) {
CellReference cellRef = new CellReference(cell.getRowIndex(), cell.getColumnIndex()); CellReference cellRef = new CellReference(cell.getRowIndex(), cell.getColumnIndex());
throw new RuntimeException("error at: " + cellRef.toString(), e); throw new RuntimeException("error at: " + cellRef.toString(), e);

View File

@ -1118,9 +1118,9 @@ public final class TestBugs extends BaseTestBugzillaIssues {
// Now evaluate, they should all be changed // Now evaluate, they should all be changed
HSSFFormulaEvaluator eval = new HSSFFormulaEvaluator(wb1); HSSFFormulaEvaluator eval = new HSSFFormulaEvaluator(wb1);
eval.evaluateFormulaCell(c1); eval.evaluateFormulaCellEnum(c1);
eval.evaluateFormulaCell(c2); eval.evaluateFormulaCellEnum(c2);
eval.evaluateFormulaCell(c3); eval.evaluateFormulaCellEnum(c3);
// Check that the cells now contain // Check that the cells now contain
// the correct values // the correct values
@ -2389,7 +2389,7 @@ public final class TestBugs extends BaseTestBugzillaIssues {
// Check the evaluated result // Check the evaluated result
HSSFFormulaEvaluator eval = new HSSFFormulaEvaluator(wb); HSSFFormulaEvaluator eval = new HSSFFormulaEvaluator(wb);
eval.evaluateFormulaCell(c); eval.evaluateFormulaCellEnum(c);
assertEquals(4.0, c.getNumericCellValue(), 0); assertEquals(4.0, c.getNumericCellValue(), 0);
wb.close(); wb.close();
} }

View File

@ -59,7 +59,7 @@ public class TestExternalReferenceChange extends TestCase {
new String[]{MAIN_WORKBOOK_FILENAME, SOURCE_WORKBOOK_FILENAME}, new String[]{MAIN_WORKBOOK_FILENAME, SOURCE_WORKBOOK_FILENAME},
new HSSFFormulaEvaluator[] {lMainWorkbookEvaluator, lSourceEvaluator}); new HSSFFormulaEvaluator[] {lMainWorkbookEvaluator, lSourceEvaluator});
assertEquals(CellType.NUMERIC, lMainWorkbookEvaluator.evaluateFormulaCell(lA1Cell)); assertEquals(CellType.NUMERIC, lMainWorkbookEvaluator.evaluateFormulaCellEnum(lA1Cell));
assertEquals(20.0d, lA1Cell.getNumericCellValue(), 0.00001d); assertEquals(20.0d, lA1Cell.getNumericCellValue(), 0.00001d);

View File

@ -287,7 +287,7 @@ public final class TestFormulaEvaluatorBugs {
HSSFRow r = (HSSFRow)rows.next(); HSSFRow r = (HSSFRow)rows.next();
for (Iterator<Cell> cells = r.cellIterator(); cells.hasNext();) { for (Iterator<Cell> cells = r.cellIterator(); cells.hasNext();) {
HSSFCell c = (HSSFCell)cells.next(); HSSFCell c = (HSSFCell)cells.next();
eval.evaluateFormulaCell(c); eval.evaluateFormulaCellEnum(c);
} }
} }
} }

View File

@ -78,10 +78,10 @@ public final class TestFormulaEvaluatorDocs extends TestCase {
for(Iterator cit = r.cellIterator(); cit.hasNext();) { for(Iterator cit = r.cellIterator(); cit.hasNext();) {
HSSFCell c = (HSSFCell)cit.next(); HSSFCell c = (HSSFCell)cit.next();
if(c.getCellTypeEnum() == CellType.FORMULA) { if(c.getCellTypeEnum() == CellType.FORMULA) {
evaluator.evaluateFormulaCell(c); evaluator.evaluateFormulaCellEnum(c);
// For testing - all should be numeric // For testing - all should be numeric
assertEquals(CellType.NUMERIC, evaluator.evaluateFormulaCell(c)); assertEquals(CellType.NUMERIC, evaluator.evaluateFormulaCellEnum(c));
} }
} }
} }

View File

@ -76,7 +76,7 @@ public final class TestHSSFFormulaEvaluator extends BaseTestFormulaEvaluator {
HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb); HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
cellA1.setCellErrorValue(FormulaError.NAME.getCode()); cellA1.setCellErrorValue(FormulaError.NAME.getCode());
fe.evaluateFormulaCell(cellB1); fe.evaluateFormulaCellEnum(cellB1);
cellA1.setCellValue(2.5); cellA1.setCellValue(2.5);
fe.notifyUpdateCell(cellA1); fe.notifyUpdateCell(cellA1);
@ -227,10 +227,10 @@ public final class TestHSSFFormulaEvaluator extends BaseTestFormulaEvaluator {
new HSSFFormulaEvaluator(wb2) new HSSFFormulaEvaluator(wb2)
} }
); );
eval.evaluateFormulaCell( eval.evaluateFormulaCellEnum(
wb1.getSheetAt(0).getRow(1).getCell(2) wb1.getSheetAt(0).getRow(1).getCell(2)
); );
eval.evaluateFormulaCell( eval.evaluateFormulaCellEnum(
wb1.getSheetAt(0).getRow(1).getCell(4) wb1.getSheetAt(0).getRow(1).getCell(4)
); );
@ -256,7 +256,7 @@ public final class TestHSSFFormulaEvaluator extends BaseTestFormulaEvaluator {
assertEquals("Cost*[XRefCalcData.xls]MarkupSheet!$B$1", cell.getCellFormula()); assertEquals("Cost*[XRefCalcData.xls]MarkupSheet!$B$1", cell.getCellFormula());
// Check it evaluates correctly // Check it evaluates correctly
eval.evaluateFormulaCell(cell); eval.evaluateFormulaCellEnum(cell);
assertEquals(24.60*1.8, cell.getNumericCellValue(), 0); assertEquals(24.60*1.8, cell.getNumericCellValue(), 0);
@ -291,7 +291,7 @@ public final class TestHSSFFormulaEvaluator extends BaseTestFormulaEvaluator {
new HSSFFormulaEvaluator(wb3) new HSSFFormulaEvaluator(wb3)
} }
); );
eval.evaluateFormulaCell(cell); eval.evaluateFormulaCellEnum(cell);
assertEquals("In another workbook", cell.getStringCellValue()); assertEquals("In another workbook", cell.getStringCellValue());
@ -310,13 +310,13 @@ public final class TestHSSFFormulaEvaluator extends BaseTestFormulaEvaluator {
// Check the one referring to the previously existing workbook behaves // Check the one referring to the previously existing workbook behaves
cell = wb4.getSheetAt(0).getRow(1).getCell(40); cell = wb4.getSheetAt(0).getRow(1).getCell(40);
assertEquals("Cost*[XRefCalcData.xls]MarkupSheet!$B$1", cell.getCellFormula()); assertEquals("Cost*[XRefCalcData.xls]MarkupSheet!$B$1", cell.getCellFormula());
eval.evaluateFormulaCell(cell); eval.evaluateFormulaCellEnum(cell);
assertEquals(24.60*1.8, cell.getNumericCellValue(), 0); assertEquals(24.60*1.8, cell.getNumericCellValue(), 0);
// Now check the newly added reference // Now check the newly added reference
cell = wb4.getSheetAt(0).getRow(1).getCell(42); cell = wb4.getSheetAt(0).getRow(1).getCell(42);
assertEquals("[alt.xls]Sheet0!$A$1", cell.getCellFormula()); assertEquals("[alt.xls]Sheet0!$A$1", cell.getCellFormula());
eval.evaluateFormulaCell(cell); eval.evaluateFormulaCellEnum(cell);
assertEquals("In another workbook", cell.getStringCellValue()); assertEquals("In another workbook", cell.getStringCellValue());
wb4.close(); wb4.close();

View File

@ -149,12 +149,12 @@ public abstract class BaseTestExternalFunctions {
Cell cell2 = sh.getRow(2).getCell(1); Cell cell2 = sh.getRow(2).getCell(1);
assertEquals("ISODD(2)", cell2.getCellFormula()); assertEquals("ISODD(2)", cell2.getCellFormula());
assertEquals(false, evaluator.evaluate(cell2).getBooleanValue()); assertEquals(false, evaluator.evaluate(cell2).getBooleanValue());
assertEquals(CellType.BOOLEAN, evaluator.evaluateFormulaCell(cell2)); assertEquals(CellType.BOOLEAN, evaluator.evaluateFormulaCellEnum(cell2));
Cell cell3 = sh.getRow(3).getCell(1); Cell cell3 = sh.getRow(3).getCell(1);
assertEquals("ISEVEN(2)", cell3.getCellFormula()); assertEquals("ISEVEN(2)", cell3.getCellFormula());
assertEquals(true, evaluator.evaluate(cell3).getBooleanValue()); assertEquals(true, evaluator.evaluate(cell3).getBooleanValue());
assertEquals(CellType.BOOLEAN, evaluator.evaluateFormulaCell(cell3)); assertEquals(CellType.BOOLEAN, evaluator.evaluateFormulaCellEnum(cell3));
wb.close(); wb.close();
} }

View File

@ -730,7 +730,7 @@ public class TestEvaluationCache extends TestCase {
//calculate //calculate
FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator(); FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator();
evaluator.evaluateFormulaCell(summaryCell); evaluator.evaluateFormulaCellEnum(summaryCell);
} }
@ -770,7 +770,7 @@ public class TestEvaluationCache extends TestCase {
//calculate //calculate
FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator(); FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator();
evaluator.evaluateFormulaCell(summaryCell); evaluator.evaluateFormulaCellEnum(summaryCell);
assertEquals(8394753.0, summaryCell.getNumericCellValue()); assertEquals(8394753.0, summaryCell.getNumericCellValue());
} }

View File

@ -69,7 +69,7 @@ public class TestMissingWorkbook extends TestCase {
assertEquals(CellType.FORMULA, lA1Cell.getCellTypeEnum()); assertEquals(CellType.FORMULA, lA1Cell.getCellTypeEnum());
try { try {
evaluator.evaluateFormulaCell(lA1Cell); evaluator.evaluateFormulaCellEnum(lA1Cell);
fail("Missing external workbook reference exception expected!"); fail("Missing external workbook reference exception expected!");
}catch(RuntimeException re) { }catch(RuntimeException re) {
assertTrue("Unexpected exception: " + re, re.getMessage().indexOf(SOURCE_DUMMY_WORKBOOK_FILENAME) != -1); assertTrue("Unexpected exception: " + re, re.getMessage().indexOf(SOURCE_DUMMY_WORKBOOK_FILENAME) != -1);
@ -95,9 +95,9 @@ public class TestMissingWorkbook extends TestCase {
FormulaEvaluator evaluator = mainWorkbook.getCreationHelper().createFormulaEvaluator(); FormulaEvaluator evaluator = mainWorkbook.getCreationHelper().createFormulaEvaluator();
evaluator.setIgnoreMissingWorkbooks(true); evaluator.setIgnoreMissingWorkbooks(true);
assertEquals(CellType.NUMERIC, evaluator.evaluateFormulaCell(lA1Cell)); assertEquals(CellType.NUMERIC, evaluator.evaluateFormulaCellEnum(lA1Cell));
assertEquals(CellType.STRING, evaluator.evaluateFormulaCell(lB1Cell)); assertEquals(CellType.STRING, evaluator.evaluateFormulaCellEnum(lB1Cell));
assertEquals(CellType.BOOLEAN, evaluator.evaluateFormulaCell(lC1Cell)); assertEquals(CellType.BOOLEAN, evaluator.evaluateFormulaCellEnum(lC1Cell));
assertEquals(10.0d, lA1Cell.getNumericCellValue(), 0.00001d); assertEquals(10.0d, lA1Cell.getNumericCellValue(), 0.00001d);
assertEquals("POI rocks!", lB1Cell.getStringCellValue()); assertEquals("POI rocks!", lB1Cell.getStringCellValue());
@ -122,9 +122,9 @@ public class TestMissingWorkbook extends TestCase {
workbooks.put(SOURCE_DUMMY_WORKBOOK_FILENAME, lSourceEvaluator); workbooks.put(SOURCE_DUMMY_WORKBOOK_FILENAME, lSourceEvaluator);
lMainWorkbookEvaluator.setupReferencedWorkbooks(workbooks); lMainWorkbookEvaluator.setupReferencedWorkbooks(workbooks);
assertEquals(CellType.NUMERIC, lMainWorkbookEvaluator.evaluateFormulaCell(lA1Cell)); assertEquals(CellType.NUMERIC, lMainWorkbookEvaluator.evaluateFormulaCellEnum(lA1Cell));
assertEquals(CellType.STRING, lMainWorkbookEvaluator.evaluateFormulaCell(lB1Cell)); assertEquals(CellType.STRING, lMainWorkbookEvaluator.evaluateFormulaCellEnum(lB1Cell));
assertEquals(CellType.BOOLEAN, lMainWorkbookEvaluator.evaluateFormulaCell(lC1Cell)); assertEquals(CellType.BOOLEAN, lMainWorkbookEvaluator.evaluateFormulaCellEnum(lC1Cell));
assertEquals(20.0d, lA1Cell.getNumericCellValue(), 0.00001d); assertEquals(20.0d, lA1Cell.getNumericCellValue(), 0.00001d);
assertEquals("Apache rocks!", lB1Cell.getStringCellValue()); assertEquals("Apache rocks!", lB1Cell.getStringCellValue());

View File

@ -511,7 +511,7 @@ public class TestWorkbookEvaluator {
Cell D1 = wb.getSheet("IFEquals").getRow(0).getCell(3); Cell D1 = wb.getSheet("IFEquals").getRow(0).getCell(3);
FormulaEvaluator eval = wb.getCreationHelper().createFormulaEvaluator(); FormulaEvaluator eval = wb.getCreationHelper().createFormulaEvaluator();
CellType resultCellType = eval.evaluateFormulaCell(D1); CellType resultCellType = eval.evaluateFormulaCellEnum(D1);
// Call should modify the contents, but leave the formula intact // Call should modify the contents, but leave the formula intact
assertEquals(CellType.FORMULA, D1.getCellTypeEnum()); assertEquals(CellType.FORMULA, D1.getCellTypeEnum());

View File

@ -66,11 +66,11 @@ public class TestRandBetween extends TestCase {
evaluator.clearAllCachedResultValues(); evaluator.clearAllCachedResultValues();
formulaCell.setCellFormula("RANDBETWEEN(1,1)"); formulaCell.setCellFormula("RANDBETWEEN(1,1)");
evaluator.evaluateFormulaCell(formulaCell); evaluator.evaluateFormulaCellEnum(formulaCell);
assertEquals(1, formulaCell.getNumericCellValue(), 0); assertEquals(1, formulaCell.getNumericCellValue(), 0);
evaluator.clearAllCachedResultValues(); evaluator.clearAllCachedResultValues();
formulaCell.setCellFormula("RANDBETWEEN(-1,-1)"); formulaCell.setCellFormula("RANDBETWEEN(-1,-1)");
evaluator.evaluateFormulaCell(formulaCell); evaluator.evaluateFormulaCellEnum(formulaCell);
assertEquals(-1, formulaCell.getNumericCellValue(), 0); assertEquals(-1, formulaCell.getNumericCellValue(), 0);
} }
@ -86,25 +86,25 @@ public class TestRandBetween extends TestCase {
topValueCell.setCellValue(0.1); topValueCell.setCellValue(0.1);
formulaCell.setCellFormula("RANDBETWEEN($A$1,$B$1)"); formulaCell.setCellFormula("RANDBETWEEN($A$1,$B$1)");
evaluator.clearAllCachedResultValues(); evaluator.clearAllCachedResultValues();
evaluator.evaluateFormulaCell(formulaCell); evaluator.evaluateFormulaCellEnum(formulaCell);
assertEquals(1, formulaCell.getNumericCellValue(), 0); assertEquals(1, formulaCell.getNumericCellValue(), 0);
bottomValueCell.setCellValue(-0.1); bottomValueCell.setCellValue(-0.1);
topValueCell.setCellValue(-0.05); topValueCell.setCellValue(-0.05);
formulaCell.setCellFormula("RANDBETWEEN($A$1,$B$1)"); formulaCell.setCellFormula("RANDBETWEEN($A$1,$B$1)");
evaluator.clearAllCachedResultValues(); evaluator.clearAllCachedResultValues();
evaluator.evaluateFormulaCell(formulaCell); evaluator.evaluateFormulaCellEnum(formulaCell);
assertEquals(0, formulaCell.getNumericCellValue(), 0); assertEquals(0, formulaCell.getNumericCellValue(), 0);
bottomValueCell.setCellValue(-1.1); bottomValueCell.setCellValue(-1.1);
topValueCell.setCellValue(-1.05); topValueCell.setCellValue(-1.05);
formulaCell.setCellFormula("RANDBETWEEN($A$1,$B$1)"); formulaCell.setCellFormula("RANDBETWEEN($A$1,$B$1)");
evaluator.clearAllCachedResultValues(); evaluator.clearAllCachedResultValues();
evaluator.evaluateFormulaCell(formulaCell); evaluator.evaluateFormulaCellEnum(formulaCell);
assertEquals(-1, formulaCell.getNumericCellValue(), 0); assertEquals(-1, formulaCell.getNumericCellValue(), 0);
bottomValueCell.setCellValue(-1.1); bottomValueCell.setCellValue(-1.1);
topValueCell.setCellValue(-1.1); topValueCell.setCellValue(-1.1);
formulaCell.setCellFormula("RANDBETWEEN($A$1,$B$1)"); formulaCell.setCellFormula("RANDBETWEEN($A$1,$B$1)");
evaluator.clearAllCachedResultValues(); evaluator.clearAllCachedResultValues();
evaluator.evaluateFormulaCell(formulaCell); evaluator.evaluateFormulaCellEnum(formulaCell);
assertEquals(-1, formulaCell.getNumericCellValue(), 0); assertEquals(-1, formulaCell.getNumericCellValue(), 0);
} }
@ -117,7 +117,7 @@ public class TestRandBetween extends TestCase {
topValueCell.setCellType(CellType.BLANK); topValueCell.setCellType(CellType.BLANK);
formulaCell.setCellFormula("RANDBETWEEN($A$1,$B$1)"); formulaCell.setCellFormula("RANDBETWEEN($A$1,$B$1)");
evaluator.clearAllCachedResultValues(); evaluator.clearAllCachedResultValues();
evaluator.evaluateFormulaCell(formulaCell); evaluator.evaluateFormulaCellEnum(formulaCell);
assertTrue(formulaCell.getNumericCellValue() == 0 || formulaCell.getNumericCellValue() == -1); assertTrue(formulaCell.getNumericCellValue() == 0 || formulaCell.getNumericCellValue() == -1);
} }
@ -130,7 +130,7 @@ public class TestRandBetween extends TestCase {
topValueCell.setCellValue(1); topValueCell.setCellValue(1);
formulaCell.setCellFormula("RANDBETWEEN($A$1,$B$1)"); formulaCell.setCellFormula("RANDBETWEEN($A$1,$B$1)");
evaluator.clearAllCachedResultValues(); evaluator.clearAllCachedResultValues();
evaluator.evaluateFormulaCell(formulaCell); evaluator.evaluateFormulaCellEnum(formulaCell);
assertEquals(CellType.ERROR, formulaCell.getCachedFormulaResultTypeEnum()); assertEquals(CellType.ERROR, formulaCell.getCachedFormulaResultTypeEnum());
assertEquals(ErrorEval.VALUE_INVALID.getErrorCode(), formulaCell.getErrorCellValue()); assertEquals(ErrorEval.VALUE_INVALID.getErrorCode(), formulaCell.getErrorCellValue());
@ -140,7 +140,7 @@ public class TestRandBetween extends TestCase {
topValueCell.setCellValue("STRING"); topValueCell.setCellValue("STRING");
formulaCell.setCellFormula("RANDBETWEEN($A$1,$B$1)"); formulaCell.setCellFormula("RANDBETWEEN($A$1,$B$1)");
evaluator.clearAllCachedResultValues(); evaluator.clearAllCachedResultValues();
evaluator.evaluateFormulaCell(formulaCell); evaluator.evaluateFormulaCellEnum(formulaCell);
assertEquals(CellType.ERROR, formulaCell.getCachedFormulaResultTypeEnum()); assertEquals(CellType.ERROR, formulaCell.getCachedFormulaResultTypeEnum());
assertEquals(ErrorEval.VALUE_INVALID.getErrorCode(), formulaCell.getErrorCellValue()); assertEquals(ErrorEval.VALUE_INVALID.getErrorCode(), formulaCell.getErrorCellValue());
@ -149,7 +149,7 @@ public class TestRandBetween extends TestCase {
topValueCell.setCellValue("STRING"); topValueCell.setCellValue("STRING");
formulaCell.setCellFormula("RANDBETWEEN($A$1,$B$1)"); formulaCell.setCellFormula("RANDBETWEEN($A$1,$B$1)");
evaluator.clearAllCachedResultValues(); evaluator.clearAllCachedResultValues();
evaluator.evaluateFormulaCell(formulaCell); evaluator.evaluateFormulaCellEnum(formulaCell);
assertEquals(CellType.ERROR, formulaCell.getCachedFormulaResultTypeEnum()); assertEquals(CellType.ERROR, formulaCell.getCachedFormulaResultTypeEnum());
assertEquals(ErrorEval.VALUE_INVALID.getErrorCode(), formulaCell.getErrorCellValue()); assertEquals(ErrorEval.VALUE_INVALID.getErrorCode(), formulaCell.getErrorCellValue());
@ -165,14 +165,14 @@ public class TestRandBetween extends TestCase {
topValueCell.setCellValue(0); topValueCell.setCellValue(0);
formulaCell.setCellFormula("RANDBETWEEN($A$1,$B$1)"); formulaCell.setCellFormula("RANDBETWEEN($A$1,$B$1)");
evaluator.clearAllCachedResultValues(); evaluator.clearAllCachedResultValues();
evaluator.evaluateFormulaCell(formulaCell); evaluator.evaluateFormulaCellEnum(formulaCell);
assertEquals(CellType.ERROR, formulaCell.getCachedFormulaResultTypeEnum()); assertEquals(CellType.ERROR, formulaCell.getCachedFormulaResultTypeEnum());
assertEquals(ErrorEval.NUM_ERROR.getErrorCode(), formulaCell.getErrorCellValue()); assertEquals(ErrorEval.NUM_ERROR.getErrorCode(), formulaCell.getErrorCellValue());
bottomValueCell.setCellValue(1); bottomValueCell.setCellValue(1);
topValueCell.setCellType(CellType.BLANK); topValueCell.setCellType(CellType.BLANK);
formulaCell.setCellFormula("RANDBETWEEN($A$1,$B$1)"); formulaCell.setCellFormula("RANDBETWEEN($A$1,$B$1)");
evaluator.clearAllCachedResultValues(); evaluator.clearAllCachedResultValues();
evaluator.evaluateFormulaCell(formulaCell); evaluator.evaluateFormulaCellEnum(formulaCell);
assertEquals(CellType.ERROR, formulaCell.getCachedFormulaResultTypeEnum()); assertEquals(CellType.ERROR, formulaCell.getCachedFormulaResultTypeEnum());
assertEquals(ErrorEval.NUM_ERROR.getErrorCode(), formulaCell.getErrorCellValue()); assertEquals(ErrorEval.NUM_ERROR.getErrorCode(), formulaCell.getErrorCellValue());
} }
@ -186,7 +186,7 @@ public class TestRandBetween extends TestCase {
topValueCell.setCellValue(Double.MAX_VALUE); topValueCell.setCellValue(Double.MAX_VALUE);
formulaCell.setCellFormula("RANDBETWEEN($A$1,$B$1)"); formulaCell.setCellFormula("RANDBETWEEN($A$1,$B$1)");
evaluator.clearAllCachedResultValues(); evaluator.clearAllCachedResultValues();
evaluator.evaluateFormulaCell(formulaCell); evaluator.evaluateFormulaCellEnum(formulaCell);
assertTrue(formulaCell.getNumericCellValue() >= Double.MIN_VALUE && formulaCell.getNumericCellValue() <= Double.MAX_VALUE); assertTrue(formulaCell.getNumericCellValue() >= Double.MIN_VALUE && formulaCell.getNumericCellValue() <= Double.MAX_VALUE);
} }

View File

@ -81,7 +81,7 @@ public final class TestIrr extends TestCase {
HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb); HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
fe.clearAllCachedResultValues(); fe.clearAllCachedResultValues();
fe.evaluateFormulaCell(cell); fe.evaluateFormulaCellEnum(cell);
double res = cell.getNumericCellValue(); double res = cell.getNumericCellValue();
assertEquals(0.143d, Math.round(res * 1000d) / 1000d); assertEquals(0.143d, Math.round(res * 1000d) / 1000d);
} }

View File

@ -121,7 +121,7 @@ public final class TestMirr extends TestCase {
HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb); HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
fe.clearAllCachedResultValues(); fe.clearAllCachedResultValues();
fe.evaluateFormulaCell(cell); fe.evaluateFormulaCellEnum(cell);
double res = cell.getNumericCellValue(); double res = cell.getNumericCellValue();
assertEquals(0.18736225093, res, 0.00000001); assertEquals(0.18736225093, res, 0.00000001);
} }

View File

@ -62,7 +62,7 @@ public final class TestNper {
assertEquals(15.0, cell.getNumericCellValue(), 0.0); assertEquals(15.0, cell.getNumericCellValue(), 0.0);
HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb); HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
fe.evaluateFormulaCell(cell); fe.evaluateFormulaCellEnum(cell);
assertEquals(CellType.ERROR, cell.getCachedFormulaResultTypeEnum()); assertEquals(CellType.ERROR, cell.getCachedFormulaResultTypeEnum());
assertEquals(FormulaError.NUM.getCode(), cell.getErrorCellValue()); assertEquals(FormulaError.NUM.getCode(), cell.getErrorCellValue());
wb.close(); wb.close();

View File

@ -50,7 +50,7 @@ public final class TestNpv extends TestCase {
// Enumeration // Enumeration
cell.setCellFormula("NPV(A2, A4,A5,A6,A7,A8)+A3"); cell.setCellFormula("NPV(A2, A4,A5,A6,A7,A8)+A3");
fe.clearAllCachedResultValues(); fe.clearAllCachedResultValues();
fe.evaluateFormulaCell(cell); fe.evaluateFormulaCellEnum(cell);
double res = cell.getNumericCellValue(); double res = cell.getNumericCellValue();
assertEquals(1922.06d, Math.round(res * 100d) / 100d); assertEquals(1922.06d, Math.round(res * 100d) / 100d);
@ -58,7 +58,7 @@ public final class TestNpv extends TestCase {
cell.setCellFormula("NPV(A2, A4:A8)+A3"); cell.setCellFormula("NPV(A2, A4:A8)+A3");
fe.clearAllCachedResultValues(); fe.clearAllCachedResultValues();
fe.evaluateFormulaCell(cell); fe.evaluateFormulaCellEnum(cell);
res = cell.getNumericCellValue(); res = cell.getNumericCellValue();
assertEquals(1922.06d, Math.round(res * 100d) / 100d); assertEquals(1922.06d, Math.round(res * 100d) / 100d);
} }

View File

@ -96,9 +96,9 @@ public final class TestExternalNameReference extends TestCase {
HSSFCell ccell = wb.getSheet(cellRef.getSheetName()).getRow(cellRef.getRow()).getCell((int)cellRef.getCol()); HSSFCell ccell = wb.getSheet(cellRef.getSheetName()).getRow(cellRef.getRow()).getCell((int)cellRef.getCol());
cellRef = new CellReference(wb.getName("TOTALCOST").getRefersToFormula()); cellRef = new CellReference(wb.getName("TOTALCOST").getRefersToFormula());
HSSFCell tccell = wb.getSheet(cellRef.getSheetName()).getRow(cellRef.getRow()).getCell((int)cellRef.getCol()); HSSFCell tccell = wb.getSheet(cellRef.getSheetName()).getRow(cellRef.getRow()).getCell((int)cellRef.getCol());
evaluator.evaluateFormulaCell(uccell); evaluator.evaluateFormulaCellEnum(uccell);
evaluator.evaluateFormulaCell(ccell); evaluator.evaluateFormulaCellEnum(ccell);
evaluator.evaluateFormulaCell(tccell); evaluator.evaluateFormulaCellEnum(tccell);
assertEquals(NEW_PART_COST, uccell.getNumericCellValue()); assertEquals(NEW_PART_COST, uccell.getNumericCellValue());
assertEquals(NEW_PART_COST*NEW_QUANT, ccell.getNumericCellValue()); assertEquals(NEW_PART_COST*NEW_QUANT, ccell.getNumericCellValue());
assertEquals(NEW_PART_COST*NEW_QUANT*MARKUP_COST_2, tccell.getNumericCellValue()); assertEquals(NEW_PART_COST*NEW_QUANT*MARKUP_COST_2, tccell.getNumericCellValue());

View File

@ -843,7 +843,7 @@ public abstract class BaseTestBugzillaIssues {
private Cell evaluateCell(Workbook wb, Cell c) { private Cell evaluateCell(Workbook wb, Cell c) {
Sheet s = c.getSheet(); Sheet s = c.getSheet();
wb.getCreationHelper().createFormulaEvaluator().evaluateFormulaCell(c); wb.getCreationHelper().createFormulaEvaluator().evaluateFormulaCellEnum(c);
return s.getRow(c.getRowIndex()).getCell(c.getColumnIndex()); return s.getRow(c.getRowIndex()).getCell(c.getColumnIndex());
} }
@ -924,8 +924,8 @@ public abstract class BaseTestBugzillaIssues {
// Try to evaluate, with the other file // Try to evaluate, with the other file
evaluator.evaluateFormulaCell(c1); evaluator.evaluateFormulaCellEnum(c1);
evaluator.evaluateFormulaCell(c2); evaluator.evaluateFormulaCellEnum(c2);
assertEquals(otherCellText, c1.getStringCellValue()); assertEquals(otherCellText, c1.getStringCellValue());
assertEquals(otherCellText, c2.getStringCellValue()); assertEquals(otherCellText, c2.getStringCellValue());
@ -1132,8 +1132,8 @@ public abstract class BaseTestBugzillaIssues {
FormulaEvaluator fe = wb.getCreationHelper().createFormulaEvaluator(); FormulaEvaluator fe = wb.getCreationHelper().createFormulaEvaluator();
assertEquals(CellType.NUMERIC, fe.evaluate(cfn).getCellType()); assertEquals(CellType.NUMERIC, fe.evaluate(cfn).getCellType());
assertEquals(CellType.STRING, fe.evaluate(cfs).getCellType()); assertEquals(CellType.STRING, fe.evaluate(cfs).getCellType());
fe.evaluateFormulaCell(cfn); fe.evaluateFormulaCellEnum(cfn);
fe.evaluateFormulaCell(cfs); fe.evaluateFormulaCellEnum(cfs);
// Now test // Now test
assertEquals(CellType.NUMERIC, cn.getCellTypeEnum()); assertEquals(CellType.NUMERIC, cn.getCellTypeEnum());
@ -1261,17 +1261,17 @@ public abstract class BaseTestBugzillaIssues {
// Check read ok, and re-evaluate fine // Check read ok, and re-evaluate fine
cell = row.getCell(5); cell = row.getCell(5);
assertEquals("ab", cell.getStringCellValue()); assertEquals("ab", cell.getStringCellValue());
ev.evaluateFormulaCell(cell); ev.evaluateFormulaCellEnum(cell);
assertEquals("ab", cell.getStringCellValue()); assertEquals("ab", cell.getStringCellValue());
cell = row.getCell(6); cell = row.getCell(6);
assertEquals("empty", cell.getStringCellValue()); assertEquals("empty", cell.getStringCellValue());
ev.evaluateFormulaCell(cell); ev.evaluateFormulaCellEnum(cell);
assertEquals("empty", cell.getStringCellValue()); assertEquals("empty", cell.getStringCellValue());
cell = row.getCell(7); cell = row.getCell(7);
assertEquals("ab", cell.getStringCellValue()); assertEquals("ab", cell.getStringCellValue());
ev.evaluateFormulaCell(cell); ev.evaluateFormulaCellEnum(cell);
assertEquals("ab", cell.getStringCellValue()); assertEquals("ab", cell.getStringCellValue());
wb2.close(); wb2.close();
} }

View File

@ -500,7 +500,7 @@ public abstract class BaseTestCell {
FormulaEvaluator fe = cellA1.getSheet().getWorkbook().getCreationHelper().createFormulaEvaluator(); FormulaEvaluator fe = cellA1.getSheet().getWorkbook().getCreationHelper().createFormulaEvaluator();
fe.evaluateFormulaCell(cellA1); fe.evaluateFormulaCellEnum(cellA1);
assertEquals("abc", cellA1.getStringCellValue()); assertEquals("abc", cellA1.getStringCellValue());
fe.evaluateInCell(cellA1); fe.evaluateInCell(cellA1);
@ -523,14 +523,14 @@ public abstract class BaseTestCell {
cellA1.setCellFormula("\"DEF\""); cellA1.setCellFormula("\"DEF\"");
fe.clearAllCachedResultValues(); fe.clearAllCachedResultValues();
fe.evaluateFormulaCell(cellA1); fe.evaluateFormulaCellEnum(cellA1);
assertEquals("DEF", cellA1.getStringCellValue()); assertEquals("DEF", cellA1.getStringCellValue());
cellA1.setCellType(CellType.STRING); cellA1.setCellType(CellType.STRING);
assertEquals("DEF", cellA1.getStringCellValue()); assertEquals("DEF", cellA1.getStringCellValue());
cellA1.setCellFormula("25.061"); cellA1.setCellFormula("25.061");
fe.clearAllCachedResultValues(); fe.clearAllCachedResultValues();
fe.evaluateFormulaCell(cellA1); fe.evaluateFormulaCellEnum(cellA1);
confirmCannotReadString(cellA1); confirmCannotReadString(cellA1);
assertEquals(25.061, cellA1.getNumericCellValue(), 0.0); assertEquals(25.061, cellA1.getNumericCellValue(), 0.0);
cellA1.setCellType(CellType.STRING); cellA1.setCellType(CellType.STRING);
@ -538,7 +538,7 @@ public abstract class BaseTestCell {
cellA1.setCellFormula("TRUE"); cellA1.setCellFormula("TRUE");
fe.clearAllCachedResultValues(); fe.clearAllCachedResultValues();
fe.evaluateFormulaCell(cellA1); fe.evaluateFormulaCellEnum(cellA1);
confirmCannotReadString(cellA1); confirmCannotReadString(cellA1);
assertEquals(true, cellA1.getBooleanCellValue()); assertEquals(true, cellA1.getBooleanCellValue());
cellA1.setCellType(CellType.STRING); cellA1.setCellType(CellType.STRING);
@ -546,7 +546,7 @@ public abstract class BaseTestCell {
cellA1.setCellFormula("#NAME?"); cellA1.setCellFormula("#NAME?");
fe.clearAllCachedResultValues(); fe.clearAllCachedResultValues();
fe.evaluateFormulaCell(cellA1); fe.evaluateFormulaCellEnum(cellA1);
confirmCannotReadString(cellA1); confirmCannotReadString(cellA1);
assertEquals(FormulaError.NAME, forInt(cellA1.getErrorCellValue())); assertEquals(FormulaError.NAME, forInt(cellA1.getErrorCellValue()));
cellA1.setCellType(CellType.STRING); cellA1.setCellType(CellType.STRING);
@ -816,7 +816,7 @@ public abstract class BaseTestCell {
Row row = sheet.createRow(0); Row row = sheet.createRow(0);
Cell cell = row.createCell(0); Cell cell = row.createCell(0);
cell.setCellFormula("SQRT(-1)"); cell.setCellFormula("SQRT(-1)");
wb.getCreationHelper().createFormulaEvaluator().evaluateFormulaCell(cell); wb.getCreationHelper().createFormulaEvaluator().evaluateFormulaCellEnum(cell);
assertEquals(36, cell.getErrorCellValue()); assertEquals(36, cell.getErrorCellValue());
} finally { } finally {
wb.close(); wb.close();

View File

@ -56,8 +56,8 @@ public abstract class BaseTestFormulaEvaluator {
FormulaEvaluator fe = wb.getCreationHelper().createFormulaEvaluator(); FormulaEvaluator fe = wb.getCreationHelper().createFormulaEvaluator();
fe.evaluateFormulaCell(c1); fe.evaluateFormulaCellEnum(c1);
fe.evaluateFormulaCell(c2); fe.evaluateFormulaCellEnum(c2);
assertEquals(6.0, c1.getNumericCellValue(), 0.0001); assertEquals(6.0, c1.getNumericCellValue(), 0.0001);
assertEquals(5.0, c2.getNumericCellValue(), 0.0001); assertEquals(5.0, c2.getNumericCellValue(), 0.0001);
@ -97,10 +97,10 @@ public abstract class BaseTestFormulaEvaluator {
// Evaluate and test // Evaluate and test
FormulaEvaluator fe = wb.getCreationHelper().createFormulaEvaluator(); FormulaEvaluator fe = wb.getCreationHelper().createFormulaEvaluator();
fe.evaluateFormulaCell(c1); fe.evaluateFormulaCellEnum(c1);
fe.evaluateFormulaCell(c2); fe.evaluateFormulaCellEnum(c2);
fe.evaluateFormulaCell(c3); fe.evaluateFormulaCellEnum(c3);
fe.evaluateFormulaCell(c4); fe.evaluateFormulaCellEnum(c4);
assertEquals(3.6, c1.getNumericCellValue(), 0.0001); assertEquals(3.6, c1.getNumericCellValue(), 0.0001);
assertEquals(17.5, c2.getNumericCellValue(), 0.0001); assertEquals(17.5, c2.getNumericCellValue(), 0.0001);
@ -289,7 +289,7 @@ public abstract class BaseTestFormulaEvaluator {
FormulaEvaluator fe = wb.getCreationHelper().createFormulaEvaluator(); FormulaEvaluator fe = wb.getCreationHelper().createFormulaEvaluator();
cellA1.setCellErrorValue(FormulaError.NAME.getCode()); cellA1.setCellErrorValue(FormulaError.NAME.getCode());
fe.evaluateFormulaCell(cellB1); fe.evaluateFormulaCellEnum(cellB1);
cellA1.setCellValue(2.5); cellA1.setCellValue(2.5);
fe.notifyUpdateCell(cellA1); fe.notifyUpdateCell(cellA1);

View File

@ -345,7 +345,7 @@ public abstract class BaseTestSheetAutosizeColumn {
for (Row r : sheet) { for (Row r : sheet) {
for (Cell c : r) { for (Cell c : r) {
if (c.getCellTypeEnum() == CellType.FORMULA){ if (c.getCellTypeEnum() == CellType.FORMULA){
eval.evaluateFormulaCell(c); eval.evaluateFormulaCellEnum(c);
} }
} }
} }