2

我正在使用office.js库开发 Office 加载项(以前称为 Office 应用程序)。

我的应用程序添加了一个处理程序以获取有关 excel 表中数据更改的通知:

Microsoft.Office.WebExtension.select("bindings#orderBinding", onBindingNotFound)        
.addHandlerAsync(
    Microsoft.Office.WebExtension.EventType.BindingDataChanged,
    (eventArgs) => {
        console.dir('Data changed in excel');
    }
);

当我在 Excel 中使用此应用程序时,它工作正常。但是当我在网络(Excel Online)中运行它时它不起作用。

在 web 中,处理程序添加成功。但是当 excel 上的数据发生变化时,不会调用处理程序。

4

1 回答 1

0

我在 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");
}

我验证在更改单元格时,事件处理程序工作正常。

验证 Excel Online 下的处理程序

于 2015-06-17T08:21:21.987 回答