0

I am using xlsx package. Please suggest any other package if available

I tried this but i am not getting complete data

var sheet, jsonData,
    excelString = new Buffer(base64, 'base64').toString('binary'),
    workbook = excelParser.read(excelString, {type: 'binary'});

    if (workbook.Sheets['Sheet1']) {
      sheet = workbook.Sheets['Sheet1'];
      workbook.Sheets['Sheet1'] = sheet;
      jsonData = excelParser.utils.sheet_to_json(workbook.Sheets['Sheet1'], {});
ManishKumar
  • 1,476
  • 2
  • 14
  • 22

3 Answers3

1

you can use

npm install excel

use this.

var parseXlsx = require('excel');
parseXlsx('Spreadsheet.xlsx', function(err, data) {
  if(err) throw err;
    // data is an array of arrays
});

and you can also visit Converting excel file to json in nodejs

Note: Make sure your Excel file is not opened by any other software (especially Excel !).

Happy coding.

Community
  • 1
  • 1
Shekhar Tyagi
  • 1,644
  • 13
  • 18
1
var XLSX = require('xlsx');
var workbook = XLSX.readFile('Test1.xlsx');

var first_sheet_name = workbook.SheetNames[0];

// to read the value of individual cell 
var address_of_cell = 'C4';
var worksheet = workbook.Sheets[first_sheet_name]; 
var desired_cell = worksheet[address_of_cell];
var desired_value = (desired_cell ? desired_cell.v : undefined);
console.log(desired_value);

For further clarification read through the documentation of xlsx https://www.npmjs.com/package/xlsx

Nikhil Jain
  • 586
  • 6
  • 21
1
var XLSX = require('xlsx');
var workbook = XLSX.readFile(path);
var sheet_name_list = workbook.SheetNames;
var xlData = XLSX.utils.sheet_to_json(workbook.Sheets[sheet_name_list[0]]);
 for (let i = 0; i < xlData.length; i++) {
            let employee_choice1 = xlData[i].employee_choice
            var employee_choice = employee_choice1.split(',')
//implement your condition

}
  • 1
    Please add some explanation to your answer such that others can learn from it – Nico Haase Apr 20 '20 at 13:49
  • "sheet_name_list" if your excel document have multiple sheets than i run a loop because it has more date than implement your checks or your condition on the basis of row column values here "employee_choice" is column name i store value in a varibale "employee_choice1" – vishal sharma Apr 20 '20 at 14:52
  • Please add this explanation **to your answer** by editing it – Nico Haase Apr 20 '20 at 15:30