Search in sources :

Example 31 with AreaEval

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

the class TestCountFuncs method testCountIfWithCriteriaReference.

/**
	 * special case where the criteria argument is a cell reference
	 */
public void testCountIfWithCriteriaReference() {
    ValueEval[] values = { new NumberEval(22), new NumberEval(25), new NumberEval(21), new NumberEval(25), new NumberEval(25), new NumberEval(25) };
    AreaEval arg0 = EvalFactory.createAreaEval("C1:C6", values);
    ValueEval criteriaArg = EvalFactory.createRefEval("A1", new NumberEval(25));
    ValueEval[] args = { arg0, criteriaArg };
    double actual = NumericFunctionInvoker.invoke(new Countif(), args);
    assertEquals(4, actual, 0D);
}
Also used : ValueEval(org.apache.poi.ss.formula.eval.ValueEval) AreaEval(org.apache.poi.ss.formula.eval.AreaEval) NumberEval(org.apache.poi.ss.formula.eval.NumberEval)

Example 32 with AreaEval

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

the class TestCountFuncs method testCaseInsensitiveStringComparison.

/**
     * String criteria in COUNTIF are case insensitive;
     * for example, the string "apples" and the string "APPLES" will match the same cells.
     */
public void testCaseInsensitiveStringComparison() {
    AreaEval range;
    ValueEval[] values;
    values = new ValueEval[] { new StringEval("no"), new StringEval("NO"), new StringEval("No"), new StringEval("Yes") };
    range = EvalFactory.createAreaEval("A1:A4", values);
    confirmCountIf(3, range, new StringEval("no"));
    confirmCountIf(3, range, new StringEval("NO"));
    confirmCountIf(3, range, new StringEval("No"));
}
Also used : ValueEval(org.apache.poi.ss.formula.eval.ValueEval) StringEval(org.apache.poi.ss.formula.eval.StringEval) AreaEval(org.apache.poi.ss.formula.eval.AreaEval)

Example 33 with AreaEval

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

the class TestCountFuncs method testCountBlank.

public void testCountBlank() {
    AreaEval range;
    ValueEval[] values;
    values = new ValueEval[] { new NumberEval(0), // note - does match blank
    new StringEval(""), BoolEval.TRUE, BoolEval.FALSE, ErrorEval.DIV_ZERO, BlankEval.instance };
    range = EvalFactory.createAreaEval("A1:B3", values);
    confirmCountBlank(2, range);
    values = new ValueEval[] { new NumberEval(0), // does match blank
    new StringEval(""), BlankEval.instance, BoolEval.FALSE, BoolEval.TRUE, BlankEval.instance };
    range = EvalFactory.createAreaEval("A1:B3", values);
    confirmCountBlank(3, range);
}
Also used : ValueEval(org.apache.poi.ss.formula.eval.ValueEval) StringEval(org.apache.poi.ss.formula.eval.StringEval) AreaEval(org.apache.poi.ss.formula.eval.AreaEval) NumberEval(org.apache.poi.ss.formula.eval.NumberEval)

Example 34 with AreaEval

use of org.apache.poi.ss.formula.eval.AreaEval 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 35 with AreaEval

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

AreaEval (org.apache.poi.ss.formula.eval.AreaEval)35 ValueEval (org.apache.poi.ss.formula.eval.ValueEval)29 NumberEval (org.apache.poi.ss.formula.eval.NumberEval)21 NumericValueEval (org.apache.poi.ss.formula.eval.NumericValueEval)17 StringEval (org.apache.poi.ss.formula.eval.StringEval)13 EvaluationException (org.apache.poi.ss.formula.eval.EvaluationException)4 I_MatchPredicate (org.apache.poi.ss.formula.functions.CountUtils.I_MatchPredicate)4 AssertionFailedError (junit.framework.AssertionFailedError)3 RefEval (org.apache.poi.ss.formula.eval.RefEval)3 ErrorEval (org.apache.poi.ss.formula.eval.ErrorEval)1 StringValueEval (org.apache.poi.ss.formula.eval.StringValueEval)1 CellRangeAddress (org.apache.poi.ss.util.CellRangeAddress)1