Search in sources :

Example 16 with ErrorEval

use of org.apache.poi.ss.formula.eval.ErrorEval in project poi by apache.

the class BaseXSSFFormulaEvaluator method evaluateFormulaCellValue.

/**
     * Returns a CellValue wrapper around the supplied ValueEval instance.
     */
protected CellValue evaluateFormulaCellValue(Cell cell) {
    EvaluationCell evalCell = toEvaluationCell(cell);
    ValueEval eval = _bookEvaluator.evaluate(evalCell);
    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() + ")");
}
Also used : BoolEval(org.apache.poi.ss.formula.eval.BoolEval) EvaluationCell(org.apache.poi.ss.formula.EvaluationCell) ValueEval(org.apache.poi.ss.formula.eval.ValueEval) CellValue(org.apache.poi.ss.usermodel.CellValue) StringEval(org.apache.poi.ss.formula.eval.StringEval) ErrorEval(org.apache.poi.ss.formula.eval.ErrorEval) NumberEval(org.apache.poi.ss.formula.eval.NumberEval)

Example 17 with ErrorEval

use of org.apache.poi.ss.formula.eval.ErrorEval in project poi by apache.

the class T method evaluate.

public ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval arg0) {
    ValueEval arg = arg0;
    if (arg instanceof RefEval) {
        // always use the first sheet
        RefEval re = (RefEval) arg;
        arg = re.getInnerValueEval(re.getFirstSheetIndex());
    } else if (arg instanceof AreaEval) {
        // when the arg is an area, choose the top left cell
        arg = ((AreaEval) arg).getRelativeValue(0, 0);
    }
    if (arg instanceof StringEval) {
        // Text values are returned unmodified
        return arg;
    }
    if (arg instanceof ErrorEval) {
        // Error values also returned unmodified
        return arg;
    }
    // for all other argument types the result is empty string
    return StringEval.EMPTY_INSTANCE;
}
Also used : RefEval(org.apache.poi.ss.formula.eval.RefEval) ValueEval(org.apache.poi.ss.formula.eval.ValueEval) StringEval(org.apache.poi.ss.formula.eval.StringEval) ErrorEval(org.apache.poi.ss.formula.eval.ErrorEval) AreaEval(org.apache.poi.ss.formula.eval.AreaEval)

Aggregations

ErrorEval (org.apache.poi.ss.formula.eval.ErrorEval)17 ValueEval (org.apache.poi.ss.formula.eval.ValueEval)13 NumberEval (org.apache.poi.ss.formula.eval.NumberEval)8 EvaluationException (org.apache.poi.ss.formula.eval.EvaluationException)5 NumericValueEval (org.apache.poi.ss.formula.eval.NumericValueEval)5 StringEval (org.apache.poi.ss.formula.eval.StringEval)5 Test (org.junit.Test)5 BoolEval (org.apache.poi.ss.formula.eval.BoolEval)2 StringValueEval (org.apache.poi.ss.formula.eval.StringValueEval)2 EvaluationCell (org.apache.poi.ss.formula.EvaluationCell)1 AreaEval (org.apache.poi.ss.formula.eval.AreaEval)1 BlankEval (org.apache.poi.ss.formula.eval.BlankEval)1 NotImplementedException (org.apache.poi.ss.formula.eval.NotImplementedException)1 RefEval (org.apache.poi.ss.formula.eval.RefEval)1 CellValue (org.apache.poi.ss.usermodel.CellValue)1