Search in sources :

Example 11 with RefEval

use of org.apache.poi.ss.formula.eval.RefEval 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)

Example 12 with RefEval

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

the class Sumproduct method getScalarValue.

private static double getScalarValue(ValueEval arg) throws EvaluationException {
    ValueEval eval;
    if (arg instanceof RefEval) {
        RefEval re = (RefEval) arg;
        if (re.getNumberOfSheets() > 1) {
            throw new EvaluationException(ErrorEval.VALUE_INVALID);
        }
        eval = re.getInnerValueEval(re.getFirstSheetIndex());
    } else {
        eval = arg;
    }
    if (eval == null) {
        throw new RuntimeException("parameter may not be null");
    }
    if (eval instanceof AreaEval) {
        AreaEval ae = (AreaEval) eval;
        // an area ref can work as a scalar value if it is 1x1
        if (!ae.isColumn() || !ae.isRow()) {
            throw new EvaluationException(ErrorEval.VALUE_INVALID);
        }
        eval = ae.getRelativeValue(0, 0);
    }
    return getProductTerm(eval, true);
}
Also used : RefEval(org.apache.poi.ss.formula.eval.RefEval) NumericValueEval(org.apache.poi.ss.formula.eval.NumericValueEval) ValueEval(org.apache.poi.ss.formula.eval.ValueEval) EvaluationException(org.apache.poi.ss.formula.eval.EvaluationException) AreaEval(org.apache.poi.ss.formula.eval.AreaEval)

Aggregations

RefEval (org.apache.poi.ss.formula.eval.RefEval)12 ValueEval (org.apache.poi.ss.formula.eval.ValueEval)9 TwoDEval (org.apache.poi.ss.formula.TwoDEval)5 EvaluationException (org.apache.poi.ss.formula.eval.EvaluationException)5 NumericValueEval (org.apache.poi.ss.formula.eval.NumericValueEval)5 NumberEval (org.apache.poi.ss.formula.eval.NumberEval)4 AreaEval (org.apache.poi.ss.formula.eval.AreaEval)3 StringEval (org.apache.poi.ss.formula.eval.StringEval)3 ThreeDEval (org.apache.poi.ss.formula.ThreeDEval)1 BlankEval (org.apache.poi.ss.formula.eval.BlankEval)1 ErrorEval (org.apache.poi.ss.formula.eval.ErrorEval)1 StringValueEval (org.apache.poi.ss.formula.eval.StringValueEval)1 ValueVector (org.apache.poi.ss.formula.functions.LookupUtils.ValueVector)1