Modify existing Excel File using node.js

后端 未结 4 1690
轻奢々
轻奢々 2021-01-03 22:38

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 se

4条回答
  •  灰色年华
    2021-01-03 23:08

    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.

提交回复
热议问题