TRY NEW VERSION

SUMIF

SUMIF(arg1, arg2, arg3) → { number | string | boolean }

Adds the cells specified by a given condition or criteria.

Parameters:

Name Type Description
arg1 ApiRange

Is the range of cells you want evaluated.

arg2 any

Is the condition or criteria in the form of a number, expression, or text that defines which cells will be added.

arg3 ApiRange

Are the actual cells to sum. If omitted, the cells in range are used.

Returns:

Type
number | string | boolean

Example

Copy code
builder.CreateFile("xlsx");
var oWorksheet = Api.GetActiveSheet();
var product = ["Product", "Apple", "Orange", "Banana"]
var totalValue = ["Total Value", "$736.00", "$924.00", "$888.00"];

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

var oFunction = Api.GetWorksheetFunction();
var oRange = oWorksheet.GetRange("B2:B4");
oWorksheet.GetRange("C4").SetValue(oFunction.SUMIF(oRange, ">800"));
builder.SaveFile("xlsx", "SUMIF.xlsx");
builder.CloseFile();

Resulting document