4

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

2 Answers 2

10

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);
Sign up to request clarification or add additional context in comments.

3 Comments

collection return as undefined
@user2848031 try it now
This is an older answer, and it did help, but the whole "let z" didn't feel comfortable. Also, this would match column "AA". Here's a one-liner update that would only get the values from column "A": const columnA = Object.keys(worksheet).filter(x => /^A\d+/.test(x)).map(x => worksheet[x].v)
2
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,
  })
);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.