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

时间:2018-01-18 09:23:53

标签: node.js excel 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...

这里有什么好建议吗?

感谢。

2 个答案:

答案 0 :(得分:2)

您可以使用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');
    })

在包的页面中查看更多信息here

here,在其他stackoverflow答案中。

希望得到这个帮助。

答案 1 :(得分:1)

您无法安装require('excel4node'),请尝试npm install excel4node进行安装