Nodejs 读写 excel 文件的最佳实践是什么?

Raz*_*Raz 2 excel node.js npm

是时候在 StackOverflow 中提问了,因为我发现了不止一个 excel 库,有些基于客户端,有些基于服务器端。

第一的

我正在使用 Node.js,在哪里首选使用 Excel 库,客户端还是服务器端?

第二

您了解并信任哪一个优秀的 Excel 库?我尝试安装这个: https: //github.com/natergj/excel4node 但不幸的是它在 CLI 中抛出下一个错误:

module.js:544
    throw err;
    ^

Error: Cannot find module 'excel4node'
    at Function.Module._resolveFilename (module.js:542:15)
    at Function.Module._load (module.js:472:25)
    at Module.require (module.js:585:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/Users/razbuchnik/node/app.js:11:10)
    at Module._compile (module.js:641:30)
    at Object.Module._extensions..js (module.js:652:10)
    at Module.load (module.js:560:32)
    at tryModuleLoad (module.js:503:12)
    at Function.Module._load (module.js:495:3)
[nodemon] app crashed - waiting for file changes before starting...
Run Code Online (Sandbox Code Playgroud)

这里有什么好的建议吗?

谢谢。

Fer*_*Paz 6

您可以使用npm install exceljs

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');
    })
Run Code Online (Sandbox Code Playgroud)

请在此处的包页面中查看更多信息。

或者在这里,在其他 stackoverflow 答案中。

希望这有帮助。