Make sure that you included JSON metadata for your custom functions. Read more about that in the Manually create JSON metadata for custom functions for more information.
For a function to work properly, you need to associate the function's id
property with the JavaScript implementation. Make sure there is an association, otherwise the function won't be registered and isn't useable in Excel. The following code sample shows how to make the association using the CustomFunctions.associate()
function. The sample defines the custom function add and associates it with the object in the JSON metadata file where the value of the id
property is ADD
.
/**
* Add two numbers
* @customfunction
* @param {number} first First number
* @param {number} second Second number
* @returns {number} The sum of the two numbers.
*/
function add(first, second) {
return first + second;
}
CustomFunctions.associate("ADD", add);
The following JSON shows the JSON metadata that is associated with the previous custom function JavaScript code.
{
"functions": [
{
"description": "Add two numbers",
"id": "ADD",
"name": "ADD",
"parameters": [
{
"description": "First number",
"name": "first",
"type": "number"
},
{
"description": "Second number",
"name": "second",
"type": "number"
}
],
"result": {
"type": "number"
}
}
]
}
Note, you can post or vote for an existing feature request on Tech Community where they are considered when the Office dev team goes through the planning process.