xlsx-populate
xlsx-populate copied to clipboard
How to store formula together with calculated value
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 ?
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.
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; } } } }