问题描述
我正在尝试从Excel.js API创建自定义函数调用方法。我遵循了Excel custom function tutorial。
但是我总是在工作表上获得错误值import { createBrowserHistory } from "history";
const history = createBrowserHistory();
export default history;
,而在调试时会收到此错误:
#VALUE!
我正在使用以下代码:
对于描述文件:
Verbose Runtime [Console] [Log] Unexpected CustomFunctions [Execution] [End] [Failure] [ExceptionThrown] Function=EXTRACTFORM ReferenceError: 'Excel' is not defined {}
Unexpected CustomFunctions [Execution] [Async] [End] [Failure] Function=EXTRACTFORM,Workbook=Book1.xlsx
js来源:
{
"functions": [
{
"id": "EXTRACTFORM","name": "EXTRACTFORM","description": "Extract formData from relaunch button","result": {
"type": "string","dimensionality": "scalar"
},"parameters": [
{
"name": "address","description": "","type": "string","dimensionality": "scalar"
}
]
}
]
}
和html:
function run(address) {
var context = new Excel.RequestContext();
var range = context.workbook.worksheets.getActiveWorksheet().getRange(address);
range.load();
return context.sync()
.then(function() {
return range.values[0][0];
});
}
CustomFunctions.associate("EXTRACTFORM",run);
感谢您的帮助!
解决方法
为了使自定义函数调用Excel.js API方法,您需要configure your add-in to use shared runtime。并且请注意,有一些limitations通过自定义函数来调用Office.js。