跳到主要内容

SUMIF

Adds the cells specified by a given condition or criteria.

Syntax

expression.SUMIF(arg1, arg2, arg3);

expression - A variable that represents a ApiWorksheetFunction class.

Parameters

NameRequired/OptionalData typeDefaultDescription
arg1RequiredApiRange | ApiNameThe range of cells to be evaluated.
arg2RequiredApiRange | ApiName | number | stringThe condition or criteria in the form of a number, expression, or text that defines which cells will be added.
arg3OptionalApiRange | ApiNameThe range to sum. If omitted, the cells in range are used.

Returns

number

Example

let worksheet = Api.GetActiveSheet();
let product = ["Product", "Apple", "range", "Banana"]
let totalValue = ["Total Value", "$736.00", "$924.00", "$888.00"];

for (let i = 0; i < product.length; i++) {
worksheet.GetRange("A" + (i + 1)).SetValue(product[i]);
}
for (let n = 0; n < totalValue.length; n++) {
worksheet.GetRange("B" + (n + 1)).SetValue(totalValue[n]);
}

let func = Api.GetWorksheetFunction();
let range = worksheet.GetRange("B2:B4");
worksheet.GetRange("C4").SetValue(func.SUMIF(range, ">800"));