I am trying to read first five rows of data from an excel sheet using xlsx module. Initially, I tried by using a sheet_to_json method which converts whole sheet data to an array of arrays.
let sheetData = xlsx.utils.sheet_to_json(workbook.Sheets[sheetsList[i]], {
header: 1,
defval: '',
blankrows: true
});
But the problem (out of memory) incurred when the file size is huge(>10K records present in a sheet).
Secondly, I tried using the following link: But I am getting the following error:
f:\xxx\node_modules\xlsx\xlsx.js:2774
function decode_range(range) { var x =range.split(":").map(decode_cell); return {s:x[0],e:x[x.length-1]}; }
^
TypeError: Cannot read property 'split' of undefined
How can I resolve it? or are they any other method or modules that are available such that I can get data from either csv, xlsx, xls?
Thanks!
I am trying to read first five rows of data from an excel sheet using xlsx module. Initially, I tried by using a sheet_to_json method which converts whole sheet data to an array of arrays.
let sheetData = xlsx.utils.sheet_to_json(workbook.Sheets[sheetsList[i]], {
header: 1,
defval: '',
blankrows: true
});
But the problem (out of memory) incurred when the file size is huge(>10K records present in a sheet).
Secondly, I tried using the following link: https://github.com/SheetJS/js-xlsx/issues/214#issuecomment-96843418 But I am getting the following error:
f:\xxx\node_modules\xlsx\xlsx.js:2774
function decode_range(range) { var x =range.split(":").map(decode_cell); return {s:x[0],e:x[x.length-1]}; }
^
TypeError: Cannot read property 'split' of undefined
How can I resolve it? or are they any other method or modules that are available such that I can get data from either csv, xlsx, xls?
Thanks!
Share Improve this question edited Aug 21, 2018 at 6:01 Almog Langleben 1485 bronze badges asked Aug 21, 2018 at 5:32 sreepurnasreepurna 1,6662 gold badges21 silver badges33 bronze badges 2- You might look into "streaming" parsers for reading your input data. Such a parser would operate on chunks of the file at a time, so you wouldn't have any out of memory errors. Looks like this npm package might do the trick. – John Ellmore Commented Aug 21, 2018 at 6:07
- @John Ellmore - Thanks for trying to help me out. But this will not solve my problem. – sreepurna Commented Aug 22, 2018 at 10:01
1 Answer
Reset to default 15Can get the first n lines of the sheet with the help of the sheetRows option that is present.
So, the code looks as follows:
let workbook = xlsx.readFile(path, {sheetRows: 5})
let sheetsList = workbook.SheetNames
let sheetData = xlsx.utils.sheet_to_json(workbook.Sheets[sheetsList[i]], {
header: 1,
defval: '',
blankrows: true
});
Here I have limited to first 5 rows.
Thanks to all who tried in solving this problem. Special thanks to xlsx community member. Here is the link: https://github.com/SheetJS/js-xlsx/issues/1225