I am looking for a way to get the last filled row in excel I.e
1. Lorem Ipsum
2. qui dolorem ipsum
.
.
nth.architecto beatae vitae <- this is the last filled row, how do I get its
number?
I am using the xlsx library for this.
I am looking for a way to get the last filled row in excel I.e
1. Lorem Ipsum
2. qui dolorem ipsum
.
.
nth.architecto beatae vitae <- this is the last filled row, how do I get its
number?
I am using the xlsx library for this.
From the example of the README
for _, sheet := range xlFile.Sheets {
for _, row := range sheet.Rows {
for _, cell := range row.Cells {
fmt.Printf("%s
", cell.String())
}
}
}
Those _ are actually indexes for the loop, which are here ignored (hence the placeholder '_
')
But nothing prevents you to use those indexes for the row part of those loops:
for _, sheet := range xlFile.Sheets {
rmax := 0
for r, row := range sheet.Rows {
for _, cell := range row.Cells {
fmt.Printf("%s
", cell.String())
// If at least one cell in this row is not empty,
// memorize current row index
if cell.String() != "" {
rmax = r
}
}
}
fmt.Printf("Last line: %d
", rmax)
}