由于我的自定义函数,我想填充几个工作表单元格,将调用函数的单元格作为基本单元格。我必须返回一些不适合一个单元格的复杂数据。
所以问题是:有没有办法在自定义函数中使用 Excel.run() ?或者有没有办法返回更复杂的数据(对象、对象数组)作为自定义函数的返回值?
这是我正在尝试做的简单示例,但它不起作用:
/**
* Adds two numbers.
* @customfunction
* @param first First number
* @param second Second number
* @returns The sum of the two numbers.
*/
async function add(first: number, second: number): Promise<void> {
return Excel.run(async context => {
const worksheet = context.workbook.worksheets.getActiveWorksheet();
const range = worksheet.getRangeByIndexes(0, 0, 1, 4);
range.values = [[1, 2, 3, 4]];
return context.sync();
})
}
CustomFunctions.associate("ADD", add);