Excel: How to determine if a cell is in edit mode prior to running context.sync()

364 Views Asked by At

an add in I'm developing is having issues with context.sync failing when a cell is in editing mode.

I would like to use delayForCellEdit in Excel.Run but it would cause the UI to hang until the user exits edit mode.

Is there a method to determine if Excel is in edit mode prior to calling context.sync?

My first inclination is to run

Excel.run(ctx => { 
  ctx.sync().then(() => { 
    console.log("not in edit mode); 
  }).catch(err => { 
    console.log("in edit mode");
  });
});

as a heartbeat every few seconds, but would like something a bit more elegant.

1

There are 1 best solutions below

6
On

Currently we only support delayForCellEdit to delay the context.sync() until exit edit mode. And I tested locally didn't meet the hang issue as you mentioned.

Here is my sample code for test and just for your reference: $("#run").click(() => tryCatch(run));

async function run() {
  await Excel.run({ delayForCellEdit: true }, async context => {
    let sheet;
    sheet = context.workbook.worksheets.getItem("Sheet1");
    let range = sheet.getRange("A1");
    range.values = [["1"]];
    await context.sync();
  }); 
}