如何解决Excel中的异步自定义函数添加总是返回#BUSY!错误
我一直在尝试使用异步自定义函数,并尝试了来自Office-add-in在线文档的样本,但是它们始终返回#BUSY !,没有异步函数可以正常工作,因此我假设清单文件已建立正确。
这是我的functions.js和functions.json文件中的示例代码。
function.js
async function getStarCount(userName,repoName) {
try {
//You can change this URL to any web request you want to work with.
const url = "https://api.github.com/repos/" + userName + "/" + repoName;
const response = await fetch(url);
//Expect that status code is in 200-299 range
if (!response.ok) {
throw new Error(response.statusText)
}
const jsonResponse = await response.json();
return jsonResponse.watchers_count;
}
catch (error) {
return error;
}
}
/**
* @customfunction
* @param address range's address
**/
async function getRangeValue (address) {
var context = new Excel.RequestContext();
var range = context.workbook.worksheets.getActiveWorksheet().getRange(address);
range.load();
await context.sync();
return range.values[0][0];
}
CustomFunctions.associate("STARCOUNT",getStarCount);
CustomFunctions.associate("RANGEVALUE",getRangeValue);
functions.json
{
"functions": [
{
"description": "Get start count","id": "STARCOUNT","name": "STARCOUNT","parameters": [
{
"description": "user name","name": "userName","type": "string"
},{
"description": "repo name","name": "repoName","type": "string"
}
],"result": {
"type": "any"
}
},{
"description": "Get value for range","id": "RANGEVALUE","name": "RANGEVALUE","parameters": [
{
"description": "address","name": "address","result": {
"type": "any"
}
}
]
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。