Sheetjs: [Help] Set headers row

Created on 1 Aug 2017  路  3Comments  路  Source: SheetJS/sheetjs

Hey!
I check the documentation to find if there is an option to define row number of headers for the readFile method, and can't find one.

For example, I have a file with the first two rows empty (or include some unused data), and the 3rd row includes the headers.
I want to be able to:

XLSX.readFile(file, { header: 3 }

Is there a way to do so?
Thanks!

Most helpful comment

Will want to use the utils function XLSX.utils.sheet_to_json

The following should get the output you are looking for:

let sheet = workbook.Sheets["SheetWithData"]
let read_data = XLSX.utils.sheet_to_json(sheet, {header: 3})

All 3 comments

Will want to use the utils function XLSX.utils.sheet_to_json

The following should get the output you are looking for:

let sheet = workbook.Sheets["SheetWithData"]
let read_data = XLSX.utils.sheet_to_json(sheet, {header: 3})

Thanks again @harmon25 !

@eyalcohen4 there are two ways to do it: at the function level (like what @harmon25 showed) or at the worksheet level.

You can directly modify the worksheet range:

var range = XLSX.utils.decode_range(worksheet['!ref']);
range.s.r = 2; // or XLSX.utils.decode_row("3");
worksheet['!ref'] = XLSX.utils.encode_range(range);

Ok! Tnx a lot

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mmancosu picture mmancosu  路  3Comments

lxzhh picture lxzhh  路  3Comments

nishthasb picture nishthasb  路  4Comments

Alex0007 picture Alex0007  路  3Comments

upasana-shah picture upasana-shah  路  4Comments