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);
}
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"));
}
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);
}
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;
}
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);
}
Aggregations