xlsx-populate icon indicating copy to clipboard operation
xlsx-populate copied to clipboard

How to store formula together with calculated value

Open k2s opened this issue 5 years ago • 2 comments

Call cell.formula('A1*10') will set formula on cell, but the result is not calculated until Calc/Excel is not used to open and save the sheet.

I need to create and load XLSX file without to open it in external application.

If I do cell.formula('A1*10').value(10) removes the formula property and I see only value 10 in the cell. Is there way to set formula and result together on cell ?

k2s avatar Apr 01 '20 14:04 k2s

I also need this kind of usage, to define the formula and save the recalculated value, as this is possible in Excel. As a workaround, I had to use https://github.com/exceljs/exceljs#formula-value because it supports setting formula and a result on the same cell, which is not possible with xlsx-populate. It seems with xlsx-populate you can set only one value in the cell.

bitconym avatar Apr 22 '20 13:04 bitconym

set fullCalcOnLoad = true, so you do not need to set formula value.

setCalcPrFullCalc(workBook) { // eslint-disable-next-line const bookNode = workBook['_node']; if (bookNode && bookNode.children) { for (let i = 0; i < bookNode.children.length; i += 1) { if (bookNode.children[i].name === 'calcPr') { bookNode.children[i].attributes.fullCalcOnLoad = 1; } } } }

guge911 avatar Mar 12 '22 08:03 guge911