как получить событие изменения данных ячейки Excel с помощью нового объекта api или Excel в office.js

Я пытаюсь узнать, как получить событие изменения ячейки с помощью объекта Excel

Excel.run(function (ctx) {

}

в офисе 2016.

контекст, используемый Office. контекст. документ такой же, как контекст, используемый в функции запуска


person shyam_    schedule 30.05.2016    source источник


Ответы (1)


нашел на это ответ. Концепция привязки, использованная ранее, теперь может использоваться также, как показано в примере https://github.com/OfficeDev/office-js-docs/blob/master/reference/excel/bindingcollection.md

(function () {
// Create myTable
Excel.run(function (ctx) {
    var table = ctx.workbook.tables.add("Sheet1!A1:C4", true);
    table.name = "myTable";
    return ctx.sync().then(function () {
        console.log("MyTable is Created!");

        //Create a new table binding for myTable
        Office.context.document.bindings.addFromNamedItemAsync("myTable", Office.CoercionType.Table, { id: "myBinding" }, function (asyncResult) {
            if (asyncResult.status == "failed") {
                console.log("Action failed with error: " + asyncResult.error.message);
            }
            else {
                // If successful, add the event handler to the table binding.
                Office.select("bindings#myBinding").addHandlerAsync(Office.EventType.BindingDataChanged, onBindingDataChanged);
            }
        });
    })
    .catch(function (error) {
        console.log(JSON.stringify(error));
    });
});

// When data in the table is changed, this event is triggered.
function onBindingDataChanged(eventArgs) {
    Excel.run(function (ctx) {
        // Highlight the table in orange to indicate data changed.
        var fill = ctx.workbook.tables.getItem("myTable").getDataBodyRange().format.fill;
        fill.load("color");
        return ctx.sync().then(function () {
            if (fill.color != "Orange") {
                ctx.workbook.bindings.getItem(eventArgs.binding.id).getTable().getDataBodyRange().format.fill.color = "Orange";

                console.log("The value in this table got changed!");
            }
            else

        })
            .then(ctx.sync)
        .catch(function (error) {
            console.log(JSON.stringify(error));
        });
    });
} 

})();

person shyam_    schedule 30.05.2016