使用Golang查找excel中最后填写的行

使用Golang查找excel中最后填写的行,excel,go,Excel,Go,我正在寻找一种方法来获取excel中最后一个填写的行,即 1. Lorem Ipsum 2. qui dolorem ipsum . . nth.architecto beatae vitae <- this is the last filled row, how do I get its number? 1。乱数假文 2.同侧阴唇 . . n.贝塔维塔建筑师 这些u实际上是循环的索引,在这里被忽略(因此占位符“”) 但没有任何东西阻止您对这些循环的行部分使用这些索引: for _,

我正在寻找一种方法来获取excel中最后一个填写的行,即

1. Lorem Ipsum
2. qui dolorem ipsum
 .
 .
nth.architecto beatae vitae <- this is the last filled row, how do I get its
number?
1。乱数假文
2.同侧阴唇
.
.
n.贝塔维塔建筑师

这些u实际上是循环的索引,在这里被忽略(因此占位符“

但没有任何东西阻止您对这些循环的行部分使用这些索引:

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)
}

您也不能在此处使用
range
,而是从末尾开始执行常规for循环,然后继续查找第一个非空行(这样您就不会浪费大量时间查看已填充的行)。
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)
}