gpt4 book ai didi

excel - 在 golang 中读取 excel 文件时出错

转载 作者:IT王子 更新时间:2023-10-29 01:58:55 24 4
gpt4 key购买 nike

我正在尝试下面的代码,但出现错误

"multiple-value cell.String() in single-value context"

代码

 package main
import (
"fmt"
"github.com/tealeg/xlsx"
)
func main() {
excelFileName := "test.xlsx"
xlFile, err := xlsx.OpenFile(excelFileName)
if err != nil {

}
for _, sheet := range xlFile.Sheets {
for _, row := range sheet.Rows {
for _, cell := range row.Cells {
fmt.Printf("%s ", cell.String(), "123")
}
fmt.Printf("\n")
}
}
}
}

最佳答案

改变

for _, cell := range row.Cells {
fmt.Printf("%s ", cell.String(), "123")
}

for _, cell := range row.Cells {
val, _ := cell.String()
fmt.Printf("%s ", val)
}

关于excel - 在 golang 中读取 excel 文件时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36646114/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com