Sai sri
Sai sri

Reputation: 545

get column names from excel using exceljs / xlsx in nodejs

I am using exceljs to fetch data from excel. I have written the below code. I am able to get the values inside the rows. But, I am not understanding how to get the column names.

let workbook = new ExcelJs.Workbook();
  workbook.xlsx.load(edata).then(async function(wb){
    wb.eachSheet((sheet, id) => {
      sheet.eachRow({ includeEmpty: false }, function(row, rowIndex) {
      console.log(row.values)
      })
    })
})

Please help me in fetching the column names. Thanks in advance!!

Upvotes: 0

Views: 4722

Answers (1)

Mauro Bagnoli
Mauro Bagnoli

Reputation: 19

Try using XLSX.utils.sheet_to_json :

const [columns] = XLSX.utils.sheet_to_json(workbook.Sheets[YOUR_SHEET_NAME], { header: 1 });

Upvotes: 1

Related Questions