Top Description Constructors Methods
org.apache.poi.ss.formula.functions

public final Class Sumproduct

extends Object
implements Function
Class Inheritance
All Implemented Interfaces
org.apache.poi.ss.formula.functions.Function
Imports
java.util.Arrays, org.apache.poi.ss.formula.TwoDEval, org.apache.poi.ss.formula.eval.AreaEval, .BlankEval, .ErrorEval, .EvaluationException, .NumberEval, .NumericValueEval, .RefEval, .StringEval, .ValueEval

Implementation for the Excel function SUMPRODUCT

Syntax :
SUMPRODUCT ( array1[, array2[, array3[, ...]]])

Parameter descriptions
array1, ... arrayN  typically area references, possibly cell references or scalar values

Let An(i,j) represent the element in the ith row jth column of the nth array
Assuming each array has the same dimensions (W, H), the result is defined as:
SUMPRODUCT = Σi: 1..H   (  Σj: 1..W   (  Πn: 1..N An(i,j)  )  )

The current implementation does not support the more advanced use cases of SUMPRODUCT, including SUMPRODUCT((B2:B9=B12)*(C2:C9=C12)*D2:D9) (see example 3 in https://support.microsoft.com/en-us/office/sumproduct-function-16753e75-9f68-4874-94ac-4d2145a2fd2e).

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private static boolean
areasAllSameSize(TwoDEval[] args, int height, int width)

public ValueEval
evaluate(ValueEval[]
the evaluated function arguments. Empty values are represented with BlankEval or MissingArgEval, never null.
args
,
int
row index of the cell containing the formula under evaluation
srcCellRow
,
int
column index of the cell containing the formula under evaluation
srcCellCol
)

Implements org.apache.poi.ss.formula.functions.Function.evaluate.

private static ValueEval
private static ValueEval
private static double
getProductTerm(ValueEval ve, boolean
false for SUMPRODUCTs over area refs.
isScalarProduct
)

Determines a double value for the specified ValueEval.

private static double
private static void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

Sumproductback to summary
public Sumproduct()

Method Detail

areasAllSameSizeback to summary
private static boolean areasAllSameSize(TwoDEval[] args, int height, int width)
evaluateback to summary
public ValueEval evaluate(ValueEval[] args, int srcCellRow, int srcCellCol)

Implements org.apache.poi.ss.formula.functions.Function.evaluate.

Parameters
args:ValueEval[]

Doc from org.apache.poi.ss.formula.functions.Function.evaluate.

the evaluated function arguments. Empty values are represented with BlankEval or MissingArgEval, never null.

srcCellRow:int

Doc from org.apache.poi.ss.formula.functions.Function.evaluate.

row index of the cell containing the formula under evaluation

srcCellCol:int

Doc from org.apache.poi.ss.formula.functions.Function.evaluate.

column index of the cell containing the formula under evaluation

Returns:ValueEval

Doc from org.apache.poi.ss.formula.functions.Function.evaluate.

The evaluated result, possibly an ErrorEval, never null

Note

- Excel uses the error code #NUM! instead of IEEE NaN, so when numeric functions evaluate to Double#NaN be sure to translate the result to ErrorEval#NUM_ERROR.

Annotations
@Override
evaluateAreaSumProductback to summary
private static ValueEval evaluateAreaSumProduct(ValueEval[] evalArgs) throws EvaluationException
evaluateSingleProductback to summary
private static ValueEval evaluateSingleProduct(ValueEval[] evalArgs) throws EvaluationException
getProductTermback to summary
private static double getProductTerm(ValueEval ve, boolean isScalarProduct) throws EvaluationException

Determines a double value for the specified ValueEval.

Parameters
isScalarProduct:boolean

false for SUMPRODUCTs over area refs.

Exceptions
EvaluationException:
if ve represents an error value.

Note - string values and empty cells are interpreted differently depending on isScalarProduct. For scalar products, if any term is blank or a string, the error (#VALUE!) is raised. For area (sum)products, if any term is blank or a string, the result is zero.

getScalarValueback to summary
private static double getScalarValue(ValueEval arg) throws EvaluationException
throwFirstErrorback to summary
private static void throwFirstError(TwoDEval areaEval) throws EvaluationException