0

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.

Space Bear
  • 755
  • 1
  • 6
  • 18

1 Answers1

0

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();
  }); 
}
  • Please add questions in comments only. – Sabito stands with Ukraine Jan 20 '21 at 06:08
  • That's unfortunate. The hang is just how our add in is coded and fetching saved data before initialization. I was hoping there was a way to detect this to display a message to the user without brute forcing it. – Space Bear Jan 20 '21 at 13:26
  • So the hang isn't related with 'delayForCellEdit', right? – ginger jiang Jan 21 '21 at 06:50
  • And for your requirement, do you mean you are fetching data to put to Excel worksheet, and you didn't want users to interrupt the progress by display a message if users try to edit the worksheet? – ginger jiang Jan 21 '21 at 06:56
  • @gingerjiang we fatch saved data at start up, so the addin hangs because we can't fetch saved data and load the UI. We also don't want users to edit a cell when loading in new data because it can be a slow process depending on the amount of data they're requesting from our service. – Space Bear Jan 22 '21 at 20:15
  • @SpaceBear, currently API cannot execute in edit mode, so seems your 'heartbeat' is the best option now. I will sync with our PM for your requirement. And also you can submit a OCV to us for the requirement! Thanks. – ginger jiang Feb 01 '21 at 02:08