使用node.js修改现有的Excel文件 [英] Modify existing Excel File using node.js

查看:1275
本文介绍了使用node.js修改现有的Excel文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以修改node.js中现有的excel文件吗? 我已经研究了exceljs,但是它不提供任何仅会修改现有数据的功能.似乎它将写入新的流.

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.

还是我错过了exceljs上的东西?

Or did I miss something on exceljs?

谢谢.

推荐答案

exceljs 确实可以让您修改Excel电子表格.

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');
    })

如果您将Streams API与exceljs一起使用,则还可以将流通过管道传输到fs.createWriteStream中,从而也可以写入文件.

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.

这篇关于使用node.js修改现有的Excel文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆