Skip to content

Recalculating formulas (without open file) #192

@jdugh

Description

@jdugh

If in your sheet1 you have a substitution in A1 like:
| ${mykey} |

And, in sheet2, you have a formula like =sheet1!A1 in B2, after running xlsx-template substitution, the Excel formula is only regenerated if you open the Excel file in MS Excel.
In my case, I need to recalculate the Excel formula without opening the file (I have a script that uses xlsx-template and publishes the result to an API for further processing).

This lib recalculates the forms:
https://github.com/fabiooshiro/xlsx-calc
Example :

const XlsxTemplate = require('xlsx-template');
const fs = require('fs');

// npm install xlsx-calc xlsx
const XLSX = require('xlsx');
const XLSX_CALC = require('xlsx-calc');

fs.readFile("test.xlsx", function(err, data) {
    var t = new XlsxTemplate(data);
    t.substitute(1, {
        myvalue: "Salut"
    });
    var newData = t.generate();
    fs.writeFileSync("result.xlsx", newData, "binary");

    // Recalculating formulas :
    var workbook = XLSX.readFile('result.xlsx');
    XLSX_CALC(workbook);
    XLSX.writeFile(workbook, 'result.xlsx')
});

Maybe we can 'copy' the source code and implement it in this library. Maybe a big job because the lib uses xlsx etc...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions