Search in sources :

Example 6 with ValueVector

use of org.apache.poi.ss.formula.functions.LookupUtils.ValueVector in project poi by apache.

the class Vlookup method evaluate.

public ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval lookup_value, ValueEval table_array, ValueEval col_index, ValueEval range_lookup) {
    try {
        // Evaluation order:
        // lookup_value , table_array, range_lookup, find lookup value, col_index, fetch result
        ValueEval lookupValue = OperandResolver.getSingleValue(lookup_value, srcRowIndex, srcColumnIndex);
        TwoDEval tableArray = LookupUtils.resolveTableArrayArg(table_array);
        boolean isRangeLookup = LookupUtils.resolveRangeLookupArg(range_lookup, srcRowIndex, srcColumnIndex);
        int rowIndex = LookupUtils.lookupIndexOfValue(lookupValue, LookupUtils.createColumnVector(tableArray, 0), isRangeLookup);
        int colIndex = LookupUtils.resolveRowOrColIndexArg(col_index, srcRowIndex, srcColumnIndex);
        ValueVector resultCol = createResultColumnVector(tableArray, colIndex);
        return resultCol.getItem(rowIndex);
    } catch (EvaluationException e) {
        return e.getErrorEval();
    }
}
Also used : ValueVector(org.apache.poi.ss.formula.functions.LookupUtils.ValueVector) TwoDEval(org.apache.poi.ss.formula.TwoDEval) ValueEval(org.apache.poi.ss.formula.eval.ValueEval) EvaluationException(org.apache.poi.ss.formula.eval.EvaluationException)

Example 7 with ValueVector

use of org.apache.poi.ss.formula.functions.LookupUtils.ValueVector in project poi by apache.

the class XYNumericFunction method evaluate.

public ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval arg0, ValueEval arg1) {
    double result;
    try {
        ValueVector vvX = createValueVector(arg0);
        ValueVector vvY = createValueVector(arg1);
        int size = vvX.getSize();
        if (size == 0 || vvY.getSize() != size) {
            return ErrorEval.NA;
        }
        result = evaluateInternal(vvX, vvY, size);
    } catch (EvaluationException e) {
        return e.getErrorEval();
    }
    if (Double.isNaN(result) || Double.isInfinite(result)) {
        return ErrorEval.NUM_ERROR;
    }
    return new NumberEval(result);
}
Also used : ValueVector(org.apache.poi.ss.formula.functions.LookupUtils.ValueVector) EvaluationException(org.apache.poi.ss.formula.eval.EvaluationException) NumberEval(org.apache.poi.ss.formula.eval.NumberEval)

Aggregations

EvaluationException (org.apache.poi.ss.formula.eval.EvaluationException)7 ValueVector (org.apache.poi.ss.formula.functions.LookupUtils.ValueVector)7 TwoDEval (org.apache.poi.ss.formula.TwoDEval)4 ValueEval (org.apache.poi.ss.formula.eval.ValueEval)4 NumberEval (org.apache.poi.ss.formula.eval.NumberEval)3 NumericValueEval (org.apache.poi.ss.formula.eval.NumericValueEval)2 RefEval (org.apache.poi.ss.formula.eval.RefEval)1 StringEval (org.apache.poi.ss.formula.eval.StringEval)1