Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recalculating formulas (without open file) #192

Open
jdugh opened this issue Mar 29, 2024 · 0 comments
Open

Recalculating formulas (without open file) #192

jdugh opened this issue Mar 29, 2024 · 0 comments

Comments

@jdugh
Copy link
Contributor

jdugh commented Mar 29, 2024

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...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant