Finds the average (arithmetic mean) for the cells specified by a given condition or criteria.
Name | Type | Description |
arg1 | ApiRange | The range of cells which will be evaluated. |
arg2 | number | string | The condition or criteria in the form of a number, expression, or text that defines which cells will be used to find the average. |
arg3 | ApiRange | The actual cells to be used to find the average. If omitted, the cells in the range are used. |
builder.CreateFile("xlsx"); var oWorksheet = Api.GetActiveSheet(); var oFunction = Api.GetWorksheetFunction(); var numbers = [67, 87, 98, 45]; for (var i = 0; i < numbers.length; i++) { oWorksheet.GetRange("A" + (i + 1)).SetValue(numbers[i]); } var oRange = oWorksheet.GetRange("A1:A4"); oWorksheet.GetRange("C1").SetValue(oFunction.AVERAGEIF(oRange, ">45")); builder.SaveFile("xlsx", "AVERAGEIF.xlsx"); builder.CloseFile();