我在Excel工作表中有一列,隨機數從100萬到100萬生成。我想閱讀這個特定的專欄,并存儲在golang的數組中。稍后,我想將此數組作為我的請求傳遞給我的負載均衡器,該負載均衡器將讀取我的列中的值并相應地進行負載均衡。我正在使用“github.com/360EntSecGroupSkylar/excelize”來創建excel文件謝謝
1 回答

MM們
TA貢獻1886條經驗 獲得超2個贊
現在我假設所有其他事情(如創建,讀取等)都超出了這個問題的范圍,并且您有一個具有當前excel文件的結構。
在這種情況下,您可以嘗試以下操作: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)
}
確保使用大寫列索引。您可以修改函數以直接獲取索引。另外,請確保以自己的方式處理錯誤。
- 1 回答
- 0 關注
- 219 瀏覽
添加回答
舉報
0/150
提交
取消