I am currently using the following code to listen for a change in Sheet1!A1:B2
:
function addEventHandler() { Office.context.document.bindings.addFromNamedItemAsync("Sheet1!A1:B2", "matrix", { id: "myBind" }, function (asyncResult) { Office.select("binding#myBind").addHandlerAsync(Office.EventType.BindingDataChanged, onBindingDataChanged2016); }) } function onBindingDataChanged2016(eventArgs) { Excel.run(function (ctx) { var foundBinding = ctx.workbook.bindings.getItem(eventArgs.binding.id); var myRange = foundBinding.getRange(); myRange.load(["address", 'values']); return ctx.sync().then(function () { console.log(JSON.stringify({ "address": myRange.address, "value": myRange.values }));
Since my reaction to change is quite expensive , I want to take it upon myself only when it is really necessary. I have two questions:
1) If I want to listen to several ranges, is it possible to define ONE listener only for "Sheet1!A1:B2, Sheet1!A9:B10, Sheet1!A100:B120"
? Should I add ONE handler for EVERY range?
2) Can I express I listen only to the change of VALUES
, not formats, etc.?
Additional question:
Is it possible to specify debounce somewhere? For instance,
we initialize the clock from 0
If the listener is running, we record the binding id
change and set the clock to 0
when the clock reaches 1 second
(i.e., it was quiet for 1 second), we respond to all recorded changes (i.e., load all changed ranges and take on a costly response)
source share