node.jsexcelexcel-formulaxlsxjs-xlsx

How to recalculate all formulas in excel file through Javascript?


I am trying to create a web app to open excel file on web page and I am using 'xlsx' module for this purpose.

The problem is when I modify any content through 'xlsx' module. Sheet formulas do not refresh.

For Instance, A1 = 2 , B1 = 2 ,C1 = sum(A1:B1) = 4. Now if I edit A1 to 3, C3 does not change to 5.

This is Object format before saving:

{
A1: {t: 'n', v: 3, w: '3'},
B1: {t: 'n', v: 2, w: '2'},
C1: {t: 'n', v: 4, f: 'sum(A1:B1)' ,w: 4}
}

A short Note: This is just a small sample code. In real project its almost impossible to manually calculate all formulas at saving stage.

And, If I had to bring 5 at C3 then I need to open that file in excel and again change A1 or B1. Is there any way to refresh all formula cells in 'xlsx'. So all formulas gets recalculated.


Solution

  • xlsx does not have the functionality for recalculating formulas. You could add and use xlsx-calc for that.

    https://github.com/fabiooshiro/xlsx-calc