我在外接程序上遇到此错误,方法是搜索特定文本,设置范围格式,然后添加命名绑定,然后添加单击绑定,从而在文本中显示特定类型的错误(可能是因为给定文档中最多50个绑定):
function highlightAndBind(text, data) {
Word.run(function (context) {
var body = context.document.body;
context.load(body, "text");
return context.sync().then(function () {
var ranges = body.search(text, { ignoreSpace: true });
context.load(ranges, "items");
return context.sync().then(function () {
if (ranges.items.length > 0) {
var range = ranges.items[0];
context.load(range, "font");
return context.sync().then(function () {
range.font.highlightColor = getColorToUseForType(data.Type);
var contentControl = range.insertContentControl();
return context.sync().then(function () {
contentControl.title = data.ID;
context.load(contentControl, 'id');
return context.sync().then(function () {
Office.context.document.bindings.addFromNamedItemAsync(contentControl.title,
Office.BindingType.Text, { id: data.ID },
function (result) {
if (result.status === Office.AsyncResultStatus.Succeeded) {
Office.select("binding#" + data.ID).addHandlerAsync(Office.EventType.BindingSelectionChanged, onBindingSelectionChanged);
return context.sync().then(function () {
});
} else {
showNotification('Error:', result.error.message);
}
}
);
});
});
});
}
});
});
}
}
关于此特定错误,我没有看到任何在线信息。我已引用office.debug.js并启用了日志记录以缩小问题范围。 90%的时间似乎要进行文本搜索:
Request:
{"AutoKeepReference":true,"Actions":[{"Id":9,"ActionType":1,"Name":"","ObjectPathId":8},{"Id":10,"ActionType":4,"Name":"IgnoreSpace","ObjectPathId":8,"ArgumentInfo":{"Arguments":[true]}},{"Id":12,"ActionType":1,"Name":"","ObjectPathId":3},{"Id":13,"ActionType":1,"Name":"","ObjectPathId":11},{"Id":14,"ActionType":3,"Name":"_KeepReference","ObjectPathId":11,"ArgumentInfo":{"Arguments":[]}},{"Id":15,"ActionType":1,"Name":"","ObjectPathId":11},{"Id":16,"ActionType":2,"Name":"","ObjectPathId":11,"QueryInfo":{"Select":["*"]},"L":[3,8,11]}],"ObjectPaths":{"3":{"Id":3,"ObjectPathType":6,"Name":"b!00000021","ArgumentInfo":{}},"8":{"Id":8,"ObjectPathType":2,"Name":"Microsoft.WordServices.SearchOptions"},"11":{"Id":11,"ObjectPathType":3,"Name":"Search","ParentObjectPathId":3,"ArgumentInfo":{"Arguments":["Text being searched for",8],"ReferencedObjectPathIds":[0,8]}}}}
Response:
{"status":"failed","error":{"name":"API Call Failed","message":"Wait until the previous call completes.","code":5100}
这是Windows桌面上的Word 2016版本1808。任何见识将不胜感激。预先感谢。