Jun 02, 2017 Get & Transform, Microsoft Excel 2016 for Mac Does Microsoft Excel 2016 for Mac have 'Get & Transform'? Specifically, does it have 'New Query' and the ability to access the 'Query Editor'? This thread is locked. You can follow the question or vote as helpful, but you cannot reply to this thread. Upload your JSON file by clicking the green button (or paste your JSON text / URL into the textbox) (Press the cog button on the right for advanced settings) Download the resulting CSV file when prompted Open your CSV file in Excel (or Open Office).
![]() -->
When an Excel custom function is written in JavaScript or TypeScript, JSDoc tags are used to provide extra information about the custom function. The JSDoc tags are then used at build time to create the JSON metadata file. Using JSDoc tags saves you from the effort of manually editing the JSON metadata file.
Important
Note that Excel custom functions are available on the following platforms.
Excel custom functions are currently not supported on iPad or in one-time purchase versions of Office 2019 or earlier.
Add the
@customfunction tag in the code comments for a JavaScript or TypeScript function to mark it as a custom function.
The function parameter types may be provided using the @param tag in JavaScript, or from the Function type in TypeScript. For more information, see the @param tag and Types sections.
Adding a description to a function
The description is displayed to the user as help text when they need help to understand what your custom function does. The description doesn't require any specific tag. Just enter a short text description in the JSDoc comment. In general the description is placed at the start of the JSDoc comment section, but it will work no matter where it is placed.
To see examples of the built-in function descriptions, open Excel, go to the Formulas tab, and choose Insert function. You can then browse through all the function descriptions, and also see your own custom functions listed.
In the following example, the phrase 'Calculates the volume of a sphere.' is the description for the custom function.
JSDoc Tags
The following JSDoc tags are supported in Excel custom functions:
@cancelable
Indicates that a custom function wants to perform an action when the function is canceled.
The last function parameter must be of type
CustomFunctions.CancelableInvocation . The function can assign a function to the oncanceled property to denote the action to perform when the function is canceled.
If the last function parameter is of type
CustomFunctions.CancelableInvocation , it will be considered @cancelable even if the tag isn't present.
A function can't have both
@cancelable and @streaming tags.
@customfunction
Syntax: @customfunction idname
Specify this tag to treat the JavaScript/TypeScript function as an Excel custom function.
This tag is required to create metadata for the custom function.
The following example shows the simplest way to declare a custom function.
id
The
id is an invariant identifier for the custom function.
In the following example, increment is the
id and the name of the function.
name
Provides the display
name for the custom function.
In the following example, INC is the
id of the function and increment is the name .
description
A description doesn't require any specific tag. Add a description to a custom function by adding a phrase to describe what the function does inside the JSDoc comment. By default, whatever text is untagged in the JSDoc comment section will be the description of the function. The description appears to users in Excel as they are entering the function. In the following example, the phrase 'A function that adds two numbers' is the description for the custom function with the id property of
ADD .
In the following example, ADD is the
id and name of the function and a description is given.
@helpurl
Syntax: @helpurl url
The provided url is displayed in Excel.
In the following example, the
helpurl is www.contoso.com/weatherhelp.
@paramJavaScript
JavaScript Syntax: @param {type} name description
To denote a custom function parameter as optional:
Note
The default value for optional parameters is
null .
The following example shows a ADD function which adds two or three numbers, with the third number as an optional parameter.
TypeScript
TypeScript Syntax: @param name description
See the Types section for more information about the function parameter types which may be used.
To denote a custom function parameter as optional, do one of the following:
For detailed description of the @param see: JSDoc
Note
The default value for optional parameters is
null .
The following example shows the
add function that adds two numbers.
@requiresAddress
Indicates that the address of the cell where the function is being evaluated should be provided.
The last function parameter must be of type
CustomFunctions.Invocation or a derived type. When the function is called, the address property will contain the address. For an example of a function that uses the @requiresAddress tag, see Addressing cell's context parameter.
@returns
Syntax: @returns {type}
Provides the type for the return value.
If
{type} is omitted, the TypeScript type info will be used. If there is no type info, the type will be any .
The following example shows the
add function that uses the @returns tag.
@streaming
Used to indicate that a custom function is a streaming function.
The last parameter should be of type
CustomFunctions.StreamingInvocation<ResultType> .The function should return void .
Streaming functions don't return values directly, but rather should call
setResult(result: ResultType) using the last parameter.
Exceptions thrown by a streaming function are ignored.
setResult() may be called with Error to indicate an error result. For an example of a streaming function and more information, see Make a streaming function.
Streaming functions can't be marked as @volatile.
@volatile
A volatile function is one whose result isn't the same from one moment to the next, even if it takes no arguments or the arguments haven't changed. Excel re-evaluates cells that contain volatile functions, together with all dependents, every time that a calculation is done. For this reason, too much reliance on volatile functions can make recalculation times slow, so use them sparingly.
Streaming functions can't be volatile.
The following function is volatile and uses the
@volatile tag.
![]() Types
By specifying a parameter type, Excel will convert values into that type before calling the function. If the type is
any , no conversion will be performed.
Value types
A single value may be represented using one of the following types:
boolean , number , string .
Matrix type
Use a two-dimensional array type to have the parameter or return value be a matrix of values. For example, the type
number[][] indicates a matrix of numbers. string[][] indicates a matrix of strings.
Error type
A non-streaming function can indicate an error by returning an Error type.
A streaming function can indicate an error by calling
setResult() with an Error type.
Promise
A function can return a Promise, which will provide the value when the promise is resolved. If the promise is rejected, then it is an error.
Other types
Any other type will be treated as an error.
Next steps
Learn about naming conventions for custom functions. Alternatively, learn how to localize your functions which requires you to write your JSON file by hand.
See also![]() Comments are closed.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
January 2023
Categories |