I need to skip first row of .xlsx file and have to consider second row as a header. Is there any utlity in js-xlsx for this?
The sheet_to_json option takes a range argument. If you set the range to 1 it will automatically skip the first row. Here's a sample XLSX file where the second row is the real "header"
title
a,b,c
1,2,3
4,5,6
7,8,9
Here's a session in node, but the same thing works in browser too:
> var XLSX = require('xlsx')
undefined
> var wb = XLSX.readFile('header_row.xlsx')
undefined
> XLSX.utils.sheet_to_json(wb.Sheets.Sheet1) // this uses the first row as the header
[ { title: 'a', undefined: 'c' },
{ title: '1', undefined: '3' },
{ title: '4', undefined: '6' },
{ title: '7', undefined: '9' } ]
> XLSX.utils.sheet_to_json(wb.Sheets.Sheet1, {range:1}) // this uses the second row
[ { a: '1', b: '2', c: '3' },
{ a: '4', b: '5', c: '6' },
{ a: '7', b: '8', c: '9' } ]
slove my problem
Most helpful comment
The
sheet_to_jsonoption takes arangeargument. If you set the range to1it will automatically skip the first row. Here's a sample XLSX file where the second row is the real "header"header_row.xlsx
Here's a session in node, but the same thing works in browser too: