我正在寻找一种方法来获取 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?
我正在使用 xlsx library为此。
最佳答案
for _, sheet := range xlFile.Sheets {
for _, row := range sheet.Rows {
for _, cell := range row.Cells {
fmt.Printf("%s\n", cell.String())
}
}
}
那些 _ 实际上是循环的索引,在这里被忽略(因此占位符 '_
')
但是没有什么能阻止您将这些索引用于这些循环的行部分:
for _, sheet := range xlFile.Sheets {
rmax := 0
for r, row := range sheet.Rows {
for _, cell := range row.Cells {
fmt.Printf("%s\n", 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\n", rmax)
}
关于excel - 使用 Golang 在 excel 中查找最后填充的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28779596/