[翻译]  Modify existing Excel File using node.js

[CHINESE]  使用node.js修改现有Excel文件


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.

有没有办法修改node.js中的现有excel文件?我已经研究过exceljs,但它没有提供任何只修改现有数据的功能。它似乎会写入新流。

Or did I miss something on exceljs?

或者我错过了exceljs的东西?

Thanks in advance.

提前致谢。

1 个解决方案

#1


16  

exceljs does let you modify Excel spreadsheets.

exceljs允许您修改Excel电子表格。

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.

如果您正在将Streams API与exceljs一起使用,您还可以将流传输到fs.createWriteStream以写入文件。


注意!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。



 
© 2014-2018 ITdaan.com 粤ICP备14056181号