AddCustomFunction

AddCustomFunction(fCustom)

Creates a new custom function. The description of the function parameters and result is specified using JSDoc. The @customfunction tag is required in JSDoc. Parameters and results can be specified as the number / string / bool / any / number[][] / string[][] / bool[][] / any[][] types. Parameters can be required or optional. A user can also set a default value.

Parameters:

Name Type Description
fCustom function

A new function for calculating.

Returns:

This method doesn't return any data.

Example

Copy code
builder.CreateFile("xlsx");
/**
* Calculates the sum of the specified numbers.
* @customfunction
* @nameLocale {fr:Ajouter | es:Añadir}
* @param {number} first The first number (required).
* @param {number} [second] The second number (optional).
* @returns {number} The sum of the numbers.
*/
Api.AddCustomFunction (function add (first, second) {
    if (second === null) {
        second = 0;
    }
    return first + second;
})
var oWorksheet = Api.GetActiveSheet();
oWorksheet.GetRange("A1").SetValue("=ADD(1, 2)");
builder.SaveFile("xlsx", "AddCustomFunction.xlsx");
builder.CloseFile();

Resulting document