我有一些go代码,它打开一个电子表格,对于每一行,使用行中的一个lanid来查找一些数据。我想将这些派生数据添加为工作表中的两个新列。
打开工作表并在所有行上循环操作都很好。我只是想不出怎么添加新列。欢迎任何建议。
下面的代码引发一个错误
恐慌:运行时错误:超出范围7的索引长度为7
就像列还没有被添加一样。
f, e := excelize.OpenFile("apps.xlsx")
if e != nil {
log.Fatal(err)
}
defer func() {
if err := f.Close(); err != nil {
fmt.Println(err)
}
}()
f.InsertCol("apps", "H")
f.InsertCol("apps", "H")
rows, err := f.GetRows("apps")
if err != nil {
fmt.Println(err)
return
}
for _, row := range rows {
lanid := row[3]
fmt.Print(lanid, "\t")
fmt.Println()
node := orgtee.lookup(lanid)
row[7] = node.title
row[8] = node.domain
}发布于 2022-02-26 13:42:07
您可以通过SetCellValue函数来设置它。
这就是例子。
for i := 1; i < len(rows); i++ {
f.SetCellValue("apps", "G"+strconv.Itoa(i), "coba1")
f.SetCellValue("apps", "H"+strconv.Itoa(i), "coba2")
f.SetCellValue("apps", "I"+strconv.Itoa(i), "coba3")
}
rows, err = f.GetRows("apps") // call GetRows again to update rows value
if err != nil {
fmt.Println(err)
return
}
fmt.Println(rows)https://stackoverflow.com/questions/71276493
复制相似问题