Does SpreadJS support synchronous calculation or a way to wait until all calcul

Posted by: dung.nguyen27 on 22 January 2026, 12:10 am EST

  • Posted 22 January 2026, 12:10 am EST

    I am implementing a workbook export feature. The workbook contains multiple sheets, and many cells include formulas for calculations.

    Before exporting, I need to overwrite the formulas with their final calculated values.

    However, the issue I am facing is that some formula cells have not been fully calculated yet at the time I retrieve their values.

    Is there any way to verify that the entire workbook has finished calculating all formulas before proceeding with the export?

  • Posted 22 January 2026, 11:58 pm EST - Updated 23 January 2026, 12:03 am EST

    Hi Dung,

    In SpreadJS, formula calculation is synchronous by default. However, if your workbook includes asynchronous or delayed formulas (for example, server-backed formulas or incremental calculation), some cells may still be pending at the time values are retrieved or exported.

    There is no single global flag that guarantees all formulas are finished in every scenario, especially when async logic is involved. The recommended approach depends on the type of formulas used:

    For purely synchronous formulas:

    Ensure calculation is triggered before export, for example, by calling spread.calculate() after all data updates and before exporting.

    For asynchronous or delayed formulas:

    Export should be synchronized with the actual completion of the calculation. A reliable pattern is to:

    • Track when async formula evaluations start and finish (e.g., using a counter in custom async functions)
    • Observe calculation progress from the workbook
    • Proceed with export only when there are no pending calculation cells and all tracked async executions are complete

    Please refer to the minimal working sample below, which demonstrates this pattern with an async formula and a calculation-complete guard before export.

    Additionally, we are implementing an event that will be triggered when all calculations are completed in SpreadJS; however, this feature is currently in our product backlog, and no ETA is available.

    Please let us know if you encounter any further issues or require additional assistance.

    Kind Regards,

    Chirag

    Attachment: https://jscodemine.mescius.io/share/DTIwwuJcQUWLPgDURCr5kw

    Working:

  • Posted 23 January 2026, 12:41 am EST

    Thank you Chirag.gupta,

    I am currently using version 17.0.10 and there is no CalculationProgress event available. Is there any way to handle this in my version?

  • Posted 23 January 2026, 2:29 am EST

    Hi Dung,

    Thank you for the clarification.

    You’re correct that in SpreadJS v17.x the CalculationProgress event is not available, so there is no built-in API in that version to directly notify when all calculations are finished.

    However, you can still reliably handle this scenario in v17 by explicitly managing async formula completion at the formula level.

    For v17, the recommended workaround is:

    1. Track asynchronous formula execution yourself: Increment a counter when an async formula starts evaluating and decrement it when the async result is set.
    2. Force SpreadJS to commit async results: When using incremental calculation, explicitly trigger:
         spread.calculate(GC.Spread.Sheets.CalculationType.minimal);
      after setting async results, to ensure the values are flushed into the workbook model.
    3. Gate export based on async completion: Only proceed with export when your async counter reaches zero, indicating that all async formulas have finished.

    This approach:

    • Works in SpreadJS v17.x
    • Does not depend on CalculationProgress
    • Ensures values retrieved before export are final

    We’ve updated the sample accordingly and attached a v17-compatible version that demonstrates:

    • Async formula tracking
    • Forcing minimal recalculation
    • Export only after all async work completes

    If upgrading is an option in the future, newer versions provide calculation lifecycle events that simplify this logic, but for v17, this pattern is a reliable solution.

    Please let us know if you require any further assistance.

    Kind regards,

    Chirag

    Attachment: WaitForCalculations.zip

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels