mirror of https://github.com/apache/poi.git
SUMIFS should not sum if a value is #N/A
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1891898 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
cd606046a2
commit
0d6bd263fe
|
@ -121,8 +121,10 @@ import org.apache.poi.ss.formula.functions.Countif.ErrorMatcher;
|
||||||
* @param ranges criteria ranges
|
* @param ranges criteria ranges
|
||||||
* @param predicates array of predicates, a predicate for each value in <code>ranges</code>
|
* @param predicates array of predicates, a predicate for each value in <code>ranges</code>
|
||||||
* @return the computed value
|
* @return the computed value
|
||||||
|
* @throws EvaluationException if there is an issue with eval
|
||||||
*/
|
*/
|
||||||
private static double aggregateMatchingCells(AreaEval sumRange, AreaEval[] ranges, I_MatchPredicate[] predicates) {
|
private static double aggregateMatchingCells(AreaEval sumRange, AreaEval[] ranges, I_MatchPredicate[] predicates)
|
||||||
|
throws EvaluationException {
|
||||||
int height = ranges[0].getHeight();
|
int height = ranges[0].getHeight();
|
||||||
int width = ranges[0].getWidth();
|
int width = ranges[0].getWidth();
|
||||||
|
|
||||||
|
@ -158,17 +160,20 @@ import org.apache.poi.ss.formula.functions.Countif.ErrorMatcher;
|
||||||
* @param relRowIndex
|
* @param relRowIndex
|
||||||
* @param relColIndex
|
* @param relColIndex
|
||||||
* @return the aggregate input value corresponding to the given range coordinates
|
* @return the aggregate input value corresponding to the given range coordinates
|
||||||
|
* @throws EvaluationException if there is an issue with eval
|
||||||
*/
|
*/
|
||||||
private static double accumulate(AreaEval sumRange, int relRowIndex, int relColIndex) {
|
private static double accumulate(AreaEval sumRange, int relRowIndex, int relColIndex) throws EvaluationException {
|
||||||
if (sumRange == null) return 1.0; // count
|
if (sumRange == null) return 1.0; // count
|
||||||
|
|
||||||
ValueEval addend = sumRange.getRelativeValue(relRowIndex, relColIndex);
|
ValueEval addend = sumRange.getRelativeValue(relRowIndex, relColIndex);
|
||||||
if (addend instanceof NumberEval) {
|
if (addend instanceof NumberEval) {
|
||||||
return ((NumberEval)addend).getNumberValue();
|
return ((NumberEval) addend).getNumberValue();
|
||||||
|
} else if (addend instanceof ErrorEval) {
|
||||||
|
throw new EvaluationException((ErrorEval)addend);
|
||||||
|
} else {
|
||||||
|
// everything else (including string and boolean values) counts as zero
|
||||||
|
return 0.0;
|
||||||
}
|
}
|
||||||
// everything else (including string and boolean values) counts as zero
|
|
||||||
return 0.0;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static AreaEval convertRangeArg(ValueEval eval) throws EvaluationException {
|
protected static AreaEval convertRangeArg(ValueEval eval) throws EvaluationException {
|
||||||
|
|
|
@ -102,8 +102,11 @@ public final class Sumif extends Var2or3ArgFunction {
|
||||||
ValueEval addend = aeSum.getRelativeValue(relRowIndex, relColIndex);
|
ValueEval addend = aeSum.getRelativeValue(relRowIndex, relColIndex);
|
||||||
if (addend instanceof NumberEval) {
|
if (addend instanceof NumberEval) {
|
||||||
return ((NumberEval) addend).getNumberValue();
|
return ((NumberEval) addend).getNumberValue();
|
||||||
|
} else if (addend instanceof ErrorEval) {
|
||||||
|
throw new EvaluationException((ErrorEval)addend);
|
||||||
} else {
|
} else {
|
||||||
throw new EvaluationException(ErrorEval.NA);
|
// everything else (including string and boolean values) counts as zero
|
||||||
|
return 0.0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue