async customFunctions 在启动时抛出意外的消息类型
async customFunctions throws Unexpected message type at startup
我有一个 CustomFunctions javascript,它与同步函数完美配合,但当我尝试使用异步函数时,我得到:“
Unhandled exception at line 21, column 707859 in https://appsforoffice.microsoft.com/lib/beta/hosted/excel-win32-16.01.js
0x800a139e - Der opstod en JavaScript-kørselsfejl: unexpected message type
”
这发生在我的 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,"unexpected message type",
"
函数的 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);
});
}
我所有的异步自定义函数都失败了!
侧边栏异步功能和同步功能一样按预期工作。
您可以尝试引用 Office.js 的以下版本吗?
http://unpkg.com/@microsoft/office-js@custom-functions-preview/dist/office.js
CDN 目前有点过时,但上面应该给你最新最好的。
UPDATE,要清楚(我不确定目前是否在文档中指出了这一点,我正在跟进):你的HTML 页面应如下所示:
<script src="https://unpkg.com/@microsoft/office-js@custom-functions-preview/dist/office.js" type="text/javascript"></script>
<script src="customfunctions.js" type="text/javascript"></script>
<script type="text/javascript">
Office.Preview.startCustomFunctions();
</script>
中间的脚本(customfunctions.js
是对您为编写这些函数而创建的任何 JavaScript 文件的引用)。
我有一个 CustomFunctions javascript,它与同步函数完美配合,但当我尝试使用异步函数时,我得到:“
Unhandled exception at line 21, column 707859 in https://appsforoffice.microsoft.com/lib/beta/hosted/excel-win32-16.01.js 0x800a139e - Der opstod en JavaScript-kørselsfejl: unexpected message type
” 这发生在我的 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,"unexpected message type", "
函数的 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);
});
}
我所有的异步自定义函数都失败了! 侧边栏异步功能和同步功能一样按预期工作。
您可以尝试引用 Office.js 的以下版本吗?
http://unpkg.com/@microsoft/office-js@custom-functions-preview/dist/office.js
CDN 目前有点过时,但上面应该给你最新最好的。
UPDATE,要清楚(我不确定目前是否在文档中指出了这一点,我正在跟进):你的HTML 页面应如下所示:
<script src="https://unpkg.com/@microsoft/office-js@custom-functions-preview/dist/office.js" type="text/javascript"></script>
<script src="customfunctions.js" type="text/javascript"></script>
<script type="text/javascript">
Office.Preview.startCustomFunctions();
</script>
中间的脚本(customfunctions.js
是对您为编写这些函数而创建的任何 JavaScript 文件的引用)。