我在 Excel Online 中测试您的代码。您报告的问题不会重现。
您可以使用“Office API 教程”应用程序验证您的代码。只需在 Onedrive 中创建一个新的 Excel 文档,然后将此应用程序插入到“插入”选项卡下的“Office 应用程序”中。
您可以粘贴任何 JavaScript 源代码并运行它。
这是我的复制步骤:
首先,创建一个绑定:
Office.context.document.bindings.addFromSelectionAsync("table", { id: "orderBinding" }, function (asyncResult) {
if (asyncResult.status == "failed") {
showMessage("Action failed with error: " + asyncResult.error.message);
}
else {
showMessage("Added new binding with type: " + asyncResult.value.type + " and id: " + asyncResult.value.id);
}
});
然后将事件处理程序分配给绑定:
Microsoft.Office.WebExtension.select("bindings#orderBinding", onBindingNotFound)
.addHandlerAsync(
Microsoft.Office.WebExtension.EventType.BindingDataChanged,
function (eventArgs){
showMessage('Data changed in excel');
}
);
function onBindingNotFound(){
showMessage("The binding object was not found. "+
"Please return to previous step to create the binding");
}
我验证在更改单元格时,事件处理程序工作正常。
