Poojan3037
Poojan3037

Reputation: 207

How to override the default behavior of suspending formula calculations during user interactions with Office JS

I am executing formulas with the help of Office JS API.

By default, Excel suspends formula calculations while the user is actively interacting with the worksheet, such as editing cell values, selecting cells, or making other changes. Once the user finishes their interaction, Excel automatically resumes the formula calculations and updates the cell values accordingly.

When I am executing formulas like web service (which fetches results online & takes time to execute) with the help of Office JS API and interacting with worksheets it does not wait for formula execution. So, Is there any way to wait for formula results while interacting with worksheets?

I am following this steps to execute formulas using Office JS API.

https://learn.microsoft.com/en-us/office/dev/add-ins/excel/excel-add-ins-ranges-set-get-values

Upvotes: 0

Views: 82

Answers (1)

Eugene Astafiev
Eugene Astafiev

Reputation: 49395

Sounds like you need to set the calculation mode in a context like in the following code:

async function setCalculationMode() {
  await Excel.run(async (context) => {
    context.application.calculationMode = Excel.CalculationMode.manual;
    await context.sync();
  });
}

Excel displays changes your add-in makes approximately as they happen in the code. For large, iterative data sets, you may not need to see this progress on the screen in real-time. Application.suspendScreenUpdatingUntilNextSync() pauses visual updates to Excel until the add-in calls context.sync(), or until Excel.run ends (implicitly calling context.sync). Be aware, Excel will not show any signs of activity until the next sync.

Read more about that in the Performance optimization using the Excel JavaScript API article.

Upvotes: 1

Related Questions