简体   繁体   English

Node.js读写Excel文件的最佳实践是什么?

[英]Nodejs what is the best practice to read and write excel files?

Its time to ask it in StackOverflow, since I have found more than one excel libraries, some based in client side and some based in server side. 是时候在StackOverflow上提出问题了,因为我发现了多个excel库,其中一些基于客户端,一些基于服务器端。

First 第一

I am using Node.js, where is preferred to use Excel libraries, client or server side? 我正在使用Node.js,在哪里最好使用Excel库(客户端或服务器端)?

Second 第二

Which is a good Excel library you know and trust? 您知道并信任哪个优秀的Excel库? I have tried to install this: https://github.com/natergj/excel4node But unfortune it throws the next error in the CLI: 我尝试安装此程序: 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...

Any good advice here? 这里有什么好的建议吗?

Thanks. 谢谢。

You can use npm install exceljs 您可以使用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');
    })

See more information here , in the package's page. 在软件包的页面中,请参阅此处的更多信息。

Or here , in other stackoverflow answer. 或者在这里 ,在其他stackoverflow答案中。

Hope this help. 希望对您有所帮助。

require('excel4node')安装require('excel4node')才能使用它,请尝试npm install excel4node进行安装

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM