You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by fa...@apache.org on 2021/07/30 12:33:16 UTC

svn commit: r1891898 - in /poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/functions: Baseifs.java Sumif.java

Author: fanningpj
Date: Fri Jul 30 12:33:15 2021
New Revision: 1891898

URL: http://svn.apache.org/viewvc?rev=1891898&view=rev
Log:
SUMIFS should not sum if a value is #N/A

Modified:
    poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/functions/Baseifs.java
    poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/functions/Sumif.java

Modified: poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/functions/Baseifs.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/functions/Baseifs.java?rev=1891898&r1=1891897&r2=1891898&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/functions/Baseifs.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/functions/Baseifs.java Fri Jul 30 12:33:15 2021
@@ -121,8 +121,10 @@ import org.apache.poi.ss.formula.functio
      * @param ranges  criteria ranges
      * @param predicates  array of predicates, a predicate for each value in <code>ranges</code>
      * @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 width = ranges[0].getWidth();
 
@@ -158,17 +160,20 @@ import org.apache.poi.ss.formula.functio
      * @param relRowIndex
      * @param relColIndex
      * @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
         
         ValueEval addend = sumRange.getRelativeValue(relRowIndex, relColIndex);
         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 {

Modified: poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/functions/Sumif.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/functions/Sumif.java?rev=1891898&r1=1891897&r2=1891898&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/functions/Sumif.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/functions/Sumif.java Fri Jul 30 12:33:15 2021
@@ -102,8 +102,11 @@ public final class Sumif extends Var2or3
             ValueEval addend = aeSum.getRelativeValue(relRowIndex, relColIndex);
             if (addend instanceof NumberEval) {
                 return ((NumberEval) addend).getNumberValue();
+            } else if (addend instanceof ErrorEval) {
+                throw new EvaluationException((ErrorEval)addend);
             } else {
-                throw new EvaluationException(ErrorEval.NA);
+                // everything else (including string and boolean values) counts as zero
+                return 0.0;
             }
         }
     }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org