Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Modify existing Excel File using node.js

Is there any way to modify existing excel file in node.js? I've looked into exceljs but it does not provide any functionality that will just modify the existing data. It seems like it will write to a new stream.

Or did I miss something on exceljs?

Thanks in advance.

like image 218
jengfad Avatar asked Sep 02 '25 02:09

jengfad


1 Answers

exceljs does let you modify Excel spreadsheets.

Here's an example of reading in an existing spreadsheet and writing it back out to a different file:

var Excel = require('exceljs');
var workbook = new Excel.Workbook();

workbook.xlsx.readFile('old.xlsx')
    .then(function() {
        var worksheet = workbook.getWorksheet(1);
        var row = worksheet.getRow(5);
        row.getCell(1).value = 5; // A5's value set to 5
        row.commit();
        return workbook.xlsx.writeFile('new.xlsx');
    })

If you're using the Streams API with exceljs, you can also pipe your stream into fs.createWriteStream to write to a file as well.

like image 70
Clarence Leung Avatar answered Sep 05 '25 13:09

Clarence Leung