我在excel表格中有一个列,它的随机数从1百万到1百万。
我想阅读这一特定列,并将其存储在戈朗的数组中。
稍后,我想将这个数组作为我的请求传递给我的负载均衡器,它将读取我列中的值并进行相应的负载平衡。
我使用“github.com/360 360EntSecGroupSkylar/excelize”创建excel文件
谢谢
发布于 2021-04-23 10:51:12
现在,我假设所有其他事情,如创建、读取等,都超出了这个问题的范围,并且您有一个具有当前excel文件的struct file。
在这种情况下,您可以尝试如下:
func GetCol(f *excelize.File, sheet string, col rune) ([]string, error) {
colIndex := int(col) - 'A'
cols, err := f.GetCols(sheet)
if err != nil {
return nil, err
}
if colIndex >= len(cols) {
return nil, errors.New("column index out of bound")
}
return cols[colIndex], nil
}如下所示:
cols, _ := GetCol(f, "Sheet1", 'B')
for _, col := range cols {
fmt.Println(col)
}确保使用大写栏索引。您可以修改该函数以直接获取索引。同时,确保以自己的方式处理错误。
https://stackoverflow.com/questions/67227403
复制相似问题