BindingDataChanged doesn't work in Excel Web A

2019-05-28 18:13发布

问题:

I'm working on an Office Add-in (formerly Apps for office) using office.js library.

My app adds a handler to get notified about data changes in excel sheet:

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

It's working fine when I'm using this app in Excel. But it doesn't work when I'm running it in the web (Excel Online).

In the web, the handler is added successfully. But the handler isn't called when data changes on the excel.

回答1:

I test your code in Excel Online. The issue you are reporting doesn't repro.

You could verify your code with the "API Tutorial for Office" app. Just create a new Excel document in Onedrive, and insert this app in "Apps for Office" under "INSERT" tab.

You could paste any JavaScript source code and run it.

Here is my repro step:

First, create a binding:

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);
    }
});

Then assign the event handler to the binding:

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

I verify that when changing the cell, the event handler is working correctly.