I have an Excel sheet which has 500 rows. I am trying to get the rows from 101 to 200.
I have searched in google, and I have found an example to get starting rows, e.g. 1 to 100 or 1 to 1000, or even 1 to any number.
But I haven't found any code to get rows from mth row to nth row (Here 'm' and 'n' can be any number eg m=101 to n=200)
Below is the code which I have found to get first 100 rows:
let workbook = XLSX.readFile('./files/uploaded_files/testfile.xlsx', {sheetRows: 100})
const wsname = workbook.SheetNames[0];
const ws = workbook.Sheets[wsname];
var exceldata = XLSX.utils.sheet_to_json(ws);
Even if there is any other module to get the rows in between, I would like to know if there is any ?
Using a smaller example of:
There are several options:
You can use your current approach and
slicethe array returned fromsheet_to_jsone.g.It's
minRow - 2to account for 1 row being headers and that the other 1 is to include row 3, not exclude it. This produces:Another option is to combine use of the
rangeandheader(see here) options.rangeallows you to control what range is considered bysheet_to_jsonandheaderis used to define the keys used in the output array of objects.You can use this after importing the whole file or continue to use the
sheetRowsoption as well e.g.:Which produces:
Noting that if you omit the
headersoption then the output is:Because the values in row 3 become the new default headers (which I think you probably don't want).
Finally, if you don't know the headers in advance you can just get an array of arrays and figure the headers out later:
Which produces: