Search code examples
node.jsexceljs

Node exceljs reading file


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?


Solution

  • 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));
            });
        });