excel - 使用 Golang 在 excel 中查找最后填充的行

标签 excel go

我正在寻找一种方法来获取 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为此。

最佳答案

来自example of the README

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/

相关文章:

go - 在 Go 中创建具有未导出子结构的结构实例

go - 不同的链接行为取决于go二进制文件的运行方式

php - Codeigniter 中 undefined variable 的问题

VBA 插件 ActiveWorkBook 何时变为事件状态?

excel - 基于文本字段的 Excel 数据透视表中的条件格式

excel - 在vba问题中选择一行

go - CGO中的C NULL类型

python - 使用 xlrd/xlwt 和循环迭代优化 Excel 数据收集/缩减

c - 如何在Golang(v1.3.2)中使用C库

go - 如何使用 godoc 创建文档?