Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get first 5 rows of each sheet? #1225

Closed
sreepurnajasti opened this issue Aug 17, 2018 · 4 comments
Closed

How to get first 5 rows of each sheet? #1225

sreepurnajasti opened this issue Aug 17, 2018 · 4 comments

Comments

@sreepurnajasti
Copy link

sreepurnajasti commented Aug 17, 2018

how can I get first 5 rows of a sheet? Right now I am using the following code which gives me whole file content in arrays.

 let workbook = xlsx.readFile(path)
 let sheetsList = workbook.SheetNames
 let sheetData = xlsx.utils.sheet_to_json(workbook.Sheets[sheetsList[i]], {
      header: 1,
      defval: '',
      blankrows: true
 });.

Thanks in advance.

@SheetJSDev
Copy link
Contributor

The readFile function takes an options argument. Using the sheetRows option
https://docs.sheetjs.com/#parsing-options , the code would be

let workbook = xlsx.readFile(path, {sheetRows: 5});

@sreepurnajasti
Copy link
Author

@SheetJSDev Thanks!!

@0APOCALYPSE0
Copy link

0APOCALYPSE0 commented Jan 14, 2022

@SheetJSDev Hi, I have one issue here. So for example, if the file size is too large like around 500Mb or more and I just want to read only like top 5 or 10 lines then, in this case, I can use sheetRows property with the read method but before that, I will read.xlsx file using FileReader as array buffer but because the file size is too large it crashing my browser or taking more than 30 minutes so how can I handle this issue. If I am trying to slice .xlsx file using slice method of a blob then it is causing this error while reading Error: Corrupted zip: can't find end of central directory

@Rohit-singh19
Copy link

Rohit-singh19 commented Jul 7, 2023

@SheetJSDev This readFile function works fine for small-size files (30MB & row 100000) but it is taking more time on large files (150 MB, around 1.5 min). Is it because it is reading the whole data first and then selecting the first selected sheetRows?
What could be the reason for the inefficiency of this function for larger files?
Regardless of the file's size, how can I read only the first selected sheetRows rows?

Thanks in advance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants