Get CountRows from sheet
Description
I need to know the number of lines, and I'm ready to offer a solution. Is this idea okay?
There are two kinds of methods to get total rows in the worksheet, for example, get the length of the trows by the GetRows function for small data scale:
f, err := excelize.OpenFile("Book1.xlsx")
if err != nil {
return
}
defer func() {
if err := f.Close(); err != nil {
fmt.Println(err)
}
}()
rows, err := f.GetRows("Sheet1")
if err != nil {
return
}
fmt.Println("total rows:", len(rows))
For better performance, please use the row iterator:
f, err := excelize.OpenFile("Book1.xlsx")
if err != nil {
return
}
defer func() {
if err := f.Close(); err != nil {
fmt.Println(err)
}
}()
var totalRows int
rows, err := f.Rows("Sheet1")
if err != nil {
return
}
for rows.Next() {
totalRows++
}
if err = rows.Close(); err != nil {
fmt.Println(err)
}
fmt.Println("total rows:", totalRows)
Thanks for the answer, the proposed options work very slowly. I did faster and ran tests. Please take a look at my solution.
https://github.com/qax-os/excelize/pull/1403
Thanks for your pull request, I've review it later.
What about read TotalRows from dimension?


What about read TotalRows from dimension?
This is optional and is not required. https://learn.microsoft.com/en-us/dotnet/api/documentformat.openxml.spreadsheet.sheetdimension?view=openxml-2.8.1#remarks
What about read TotalRows from dimension?
This is optional and is not required. https://learn.microsoft.com/en-us/dotnet/api/documentformat.openxml.spreadsheet.sheetdimension?view=openxml-2.8.1#remarks
What a pity :(