From: PJ Fanning Date: Fri, 30 Jul 2021 11:03:33 +0000 (+0000) Subject: [bug-65475] SUMIF should return #N/A if any of the amounts to sum is #N/A. Thanks... X-Git-Tag: REL_5_1_0~94 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=979444134ef4be0f36b6f578cec9c401178282e9;p=poi.git [bug-65475] SUMIF should return #N/A if any of the amounts to sum is #N/A. Thanks to zhangyajun. git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1891896 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/poi/src/main/java/org/apache/poi/ss/formula/functions/Sumif.java b/poi/src/main/java/org/apache/poi/ss/formula/functions/Sumif.java index e9cd37fdcc..e9a9f2c9c9 100644 --- a/poi/src/main/java/org/apache/poi/ss/formula/functions/Sumif.java +++ b/poi/src/main/java/org/apache/poi/ss/formula/functions/Sumif.java @@ -66,45 +66,46 @@ public final class Sumif extends Var2or3ArgFunction { return eval(srcRowIndex, srcColumnIndex, arg1, aeRange, aeSum); } - private static ValueEval eval(int srcRowIndex, int srcColumnIndex, ValueEval arg1, AreaEval aeRange, - AreaEval aeSum) { - // TODO - junit to prove last arg must be srcColumnIndex and not srcRowIndex + private static ValueEval eval(int srcRowIndex, int srcColumnIndex, ValueEval arg1, AreaEval aeRange, AreaEval aeSum) { I_MatchPredicate mp = Countif.createCriteriaPredicate(arg1, srcRowIndex, srcColumnIndex); - - // handle empty cells - if(mp == null) { + if (mp == null) { return NumberEval.ZERO; - } + } else { + try { + double result = sumMatchingCells(aeRange, mp, aeSum); + return new NumberEval(result); + } catch (EvaluationException var) { + return var.getErrorEval(); + } - double result = sumMatchingCells(aeRange, mp, aeSum); - return new NumberEval(result); + } } - private static double sumMatchingCells(AreaEval aeRange, I_MatchPredicate mp, AreaEval aeSum) { - int height=aeRange.getHeight(); - int width= aeRange.getWidth(); + private static double sumMatchingCells(AreaEval aeRange, I_MatchPredicate mp, AreaEval aeSum) throws EvaluationException { + int height = aeRange.getHeight(); + int width = aeRange.getWidth(); + double result = 0.0D; - double result = 0.0; - for (int r=0; r