jbillay
jbillay

Reputation: 43

Edit xlsx file without lost format and formulas with XLSX.js

I need to edit a XLSX file in a nodejs application for create an order sheet. the file I need to edit have a specific format and some formulas. I try to use several libraries but the only one I found that able to read and write xlsx files is XLSX.js.

But when I try to read the xlsx file and write the same content in a file, I lost the format and all formulas on the new file. Please find hereunder the piece of code that I use :

var xl = require('../public/javascripts/xlsx'),
    fs = require('fs-extra'),
    inFile = 'conf/X-Pole_Order_Form.xlsx',
    outFile = "conf/tmp.xlsx";

fs.copy(inFile, outFile, function (err) {
    if (err) {
        throw new Error('Not enable to copy excel file');
    }
    fs.readFile(outFile, 'base64', function (err, content) {
        if (err) {
            throw new Error('Problem by reading excel file');
        }
        var sheet = xl(content);
        fs.writeFile(outFile, sheet.base64, 'base64');
    });
});

Do you have any idea or other solution to propose ?

Thanks for your help.

Upvotes: 3

Views: 3599

Answers (1)

Chris Haas
Chris Haas

Reputation: 55417

According to this two year old blog post by the author of that library (emphasis mine):

Right now XLSX.js supports reading data from multiple worksheets, the names of the worksheets, the active worksheet, and file metadata. It does not support the reading of formatting information, macros, charts, or anything else.

Reading through the changelog for that file I don't see much was added that is format related. There is a pull request from someone that adds a little bit of formatting that you could try to implement but I don't think you're going to get full-blown Excel formatting from this library anytime soon.

Upvotes: 2

Related Questions