Node exceljs reading file

Marc Rasmussen picture Marc Rasmussen · Mar 4, 2015 · Viewed 41.1k times · Source

So according to the offical documentation i should be able to read an excel document using:

    // read from a file 
var workbook = new Excel.Workbook();
workbook.xlsx.readFile(filename)
    .then(function() {
        // use workbook 
    });

// pipe from stream 
var workbook = new Excel.Workbook();
stream.pipe(workbook.xlsx.createInputStream());

I have the following document:

enter image description here

What i need to do is basicly to load each row into an object:

var excelObject = {competence1: '', competence2: ''}

And then save it into an array.

However the documentation doesnt give me more on how i might read from this file. It uses a variable called stream however this variable is not explained anywhere.

Does anyone know the plugin and know how i might achieve my goal?

Answer

Diogo Cardoso picture Diogo Cardoso · Nov 6, 2015
var workbook = new Excel.Workbook(); 
workbook.xlsx.readFile(filename)
    .then(function() {
        var worksheet = workbook.getWorksheet(sheet);
        worksheet.eachRow({ includeEmpty: true }, function(row, rowNumber) {
          console.log("Row " + rowNumber + " = " + JSON.stringify(row.values));
        });
    });