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

Is there anyway to read top N rows ? #146

Closed
shawnye opened this issue Nov 5, 2017 · 3 comments
Closed

Is there anyway to read top N rows ? #146

shawnye opened this issue Nov 5, 2017 · 3 comments
Labels
enhancement New feature or request

Comments

@shawnye
Copy link

shawnye commented Nov 5, 2017

Suppose there is big files containing 500,000 rows , I just want to read top 1000 rows, could you provide the method like ReadTop(sheetName string, rows int) [][]string , maybe you could use xml stream reading to save a lot of memory than I do with GetRows().

Thanks.

@xuri xuri added the enhancement New feature or request label Nov 6, 2017
@lalvarezguillen
Copy link

This would be a very interesting feature.

@kharism
Copy link

kharism commented Mar 5, 2018

I've build a library to do that, as long as not many cells using string it can do just that. https://github.com/eaciit/hoboexcel. It stream the data directly from excel. only shared strings is being extracted and partitioned into files to save ram

@xuri
Copy link
Member

xuri commented Nov 22, 2019

Hi @shawnye, thanks for your issue, sorry for my late reply. I have made the function GetRow and Rows read data as streaming. You can get all the data in the worksheet at once through GetRows, or read the data row by row using Rows and Next like this:

// read top 10 rows
rows, err := f.Rows("Sheet1")
if err != nil {
    fmt.Println(err)
    return
}
for rows.Next() {
    count++
    if count > 10 {
        break
    }
    row, _ := rows.Columns()
    for _, colCell := range row {
        fmt.Print(colCell, "\t")
    }
    fmt.Println()
}

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

No branches or pull requests

4 participants