我有一个 CustomFunctions javascript,它可以与同步函数完美配合,但是一旦我尝试使用 Async 函数,我就会得到:“
https://appsforoffice.microsoft.com/lib/beta/hosted/excel-win32-16.01.js 0x800a139e第 21 行第 707859 列未处理的异常 - Der opstod en JavaScript-kørselsfejl:意外消息类型
“这发生在对我的 js 文件调用任何 javascript 代码之前。消息类型是 1002,因此在 excel-win-16.01.js 中指定位置的 javascript 中,当然会抛出错误:”
if(i[t].messageType===1001)u.push(i[t]);else throw OfficeExtension.Utility.createRuntimeError(st.generalException,"意外消息类型","
该函数的 json 描述为:
{
"name": "helloasync",
"description": "simple test string return",
"helpUrl": "https://www.konsolidator.com",
"result": {
"type": "string",
"dimensionality": "scalar"
},
"parameters": [],
"options": {"sync": false}
},
{
"name": "ADD42ASYNC",
"description": "asynchronously wait 250ms, then add 42",
"helpUrl": "http://dev.office.com",
"result": {
"type": "number",
"dimensionality": "scalar"
},
"parameters": [
{
"name": "num",
"description": "Number",
"type": "number",
"dimensionality": "scalar"
}
],
"options": {
"sync": false
}
}
JS代码:
function helloasync() {
return new OfficeExtension.Promise(function (setResult) {
setTimeout(function () {
setResult("hello");
}, 1000);
});
}
function ADD42ASYNC(num) {
// waits 1 second before returning the result
return new OfficeExtension.Promise(function (resolve,reject) {
//resolve(num);
//reject(num);
setTimeout(function () {
resolve(num + 42);
}, 1000);
});
}
我所有的异步自定义函数都失败了!侧边栏异步函数和同步函数一样工作。