Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read only column A value from excel using nodejs?

How to read only Column A value from excel using nodejs(node-xlsx) ? Please advise. After reading all the column values then loop through to search from other source.

var xlsx = require('node-xlsx');
var obj = xlsx.parse(__dirname + '/test.xlsx'); 
var obj = xlsx.parse(fs.readFileSync(__dirname + '/test.xlsx')); 
console.log(JSON.stringify(obj));
like image 562
user2848031 Avatar asked Feb 06 '23 16:02

user2848031


2 Answers

Try other npm package called: xlsx:

'use strict';

const _ = require('lodash');
const xlsx = require('xlsx');

const workbook = xlsx.readFile('./data/pv.xlsx');
const worksheet = workbook.Sheets[workbook.SheetNames[0]];

const columnA = [];

for (let z in worksheet) {
  if(z.toString()[0] === 'A'){
    columnA.push(worksheet[z].v);
  }
}

console.log(columnA);
like image 97
Niezborala Avatar answered Feb 08 '23 10:02

Niezborala


const XLSX = require("xlsx");

const workbook = XLSX.readFile("DummyExcel.xlxs"); //read the file
const worksheet = workbook.Sheets["Execution Summary"]; //get the worksheet by name. you can put sheet id also

//print the value of desired cell or range of cell
console.log(
  "worksheet:",
  XLSX.utils.sheet_to_json(worksheet, {
    raw: true,
    range: "B5:B10",
      defval: null,
  })
);
like image 44
Rajesh kumar Avatar answered Feb 08 '23 10:02

Rajesh kumar