Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

node.js

npm

excel

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.

First

I am using Node.js, where is preferred to use Excel libraries, client or server side?

Second

Which is a good Excel library you know and trust? I have tried to install this: https://github.com/natergj/excel4node But unfortune it throws the next error in the 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.

like image 298
Raz Avatar asked Oct 19 '25 21:10

Raz


2 Answers

You can use 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.

Hope this help.

like image 156
Fernando Paz Avatar answered Oct 22 '25 12:10

Fernando Paz


You can't use require('excel4node') without install it, try npm install excel4node to install it

like image 35
Shigehiro Kamisama Avatar answered Oct 22 '25 13:10

Shigehiro Kamisama



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!