CustomFunctions.Invocation interface
提供有关调用自定义函数的信息。
注解
示例
/**
* Return the address of the cell that invoked the custom function.
* @customfunction
* @param {number} first First parameter.
* @param {number} second Second parameter.
* @param {CustomFunctions.Invocation} invocation Invocation object.
* @requiresAddress
*/
function getAddress(first, second, invocation) {
const address = invocation.address;
return address;
}
属性
address | 调用函数的单元格地址(如果请求),否则为未定义。 若要请求函数的地址,请在元数据 JSON 文件中,函数选项应指定: 如果元数据 JSON 文件是从 JSDoc 注释生成的,请包含 标记 |
function |
此函数的名称。 |
is |
指示是否在公式值预览中调用函数。
|
parameter |
如果请求,范围将定位函数参数所在的位置,否则为未定义。 若要请求函数的参数地址,请在元数据 JSON 文件中,函数选项应指定: 如果元数据 JSON 文件是从 JSDoc 注释生成的,请包含 标记 |
属性详细信息
address
调用函数的单元格地址(如果请求),否则为未定义。
若要请求函数的地址,请在元数据 JSON 文件中,函数选项应指定: { "requiresAddress": true }
如果元数据 JSON 文件是从 JSDoc 注释生成的,请包含 标记 @requiresAddress
。
address?: string;
属性值
string
注解
[ API set: CustomFunctionsRuntime 1.1 ]
示例
/**
* Return the address of the cell that invoked the custom function.
* @customfunction
* @param {number} first First parameter.
* @param {number} second Second parameter.
* @param {CustomFunctions.Invocation} invocation Invocation object.
* @requiresAddress
*/
function getAddress(first, second, invocation) {
const address = invocation.address;
return address;
}
functionName
isInValuePreview
指示是否在公式值预览中调用函数。
isInValuePreview
是只读的,不能由自定义函数加载项设置。 如果调用函数来预览公式值,则此值 true
为 ;否则为 false
。
isInValuePreview?: string;
属性值
string
注解
[ API set: CustomFunctionsRuntime 1.5 ]
示例
/**
* Get the listing price for a house on the market for the given address.
* @customfunction
* @param address The address of the house.
* @param invocation Custom function handler.
* @returns The price of the house at the address.
*/
function getHousePrice(address: string, invocation: CustomFunctions.Invocation): number {
// Check if this call is for formula value preview mode.
if (invocation.isInValuePreview) {
// Avoid long-running expensive service calls.
// Return a usable but fake number.
return 450000;
} else {
// Make the actual service calls in this block.
const price = callHouseServiceAPI(address);
return price;
}
}
parameterAddresses
如果请求,范围将定位函数参数所在的位置,否则为未定义。
若要请求函数的参数地址,请在元数据 JSON 文件中,函数选项应指定: { "requiresParameterAddresses": true }
如果元数据 JSON 文件是从 JSDoc 注释生成的,请包含 标记 @requiresParameterAddresses
。
parameterAddresses?: string[];
属性值
string[]
注解
[ API set: CustomFunctionsRuntime 1.3 ]
示例
/**
* Return the addresses of three parameters.
* @customfunction
* @param {string} firstParameter First parameter.
* @param {string} secondParameter Second parameter.
* @param {string} thirdParameter Third parameter.
* @param {CustomFunctions.Invocation} invocation Invocation object.
* @returns {string[][]} The addresses of the parameters, as a 2-dimensional array.
* @requiresParameterAddresses
*/
function getParameterAddresses(firstParameter, secondParameter, thirdParameter, invocation) {
const addresses = [
[invocation.parameterAddresses[0]],
[invocation.parameterAddresses[1]],
[invocation.parameterAddresses[2]]
];
return addresses;
}