Skip to content

Is there anyway to read top N rows ? #146

@shawnye

Description

@shawnye

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.

Activity

lalvarezguillen

lalvarezguillen commented on Nov 17, 2017

@lalvarezguillen

This would be a very interesting feature.

kharism

kharism commented on Mar 5, 2018

@kharism

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

xuri commented on Nov 22, 2019

@xuri
Member

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()
}
added a commit that references this issue on Oct 23, 2020
1f74ef3
added a commit that references this issue on Mar 14, 2024
7965e12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @shawnye@xuri@kharism@lalvarezguillen

        Issue actions

          Is there anyway to read top N rows ? · Issue #146 · qax-os/excelize