使用go-excelize读取Excel指定列的数据
func ListCol(excel_path, col string) []string {
colNum := map[string]int{
"A": 0,
"B": 1,
"C": 2,
"D": 3,
"E": 4,
"F": 5,
"G": 6,
"H": 7,
"I": 8,
"J": 9,
"K": 10,
"L": 11,
"M": 12,
"N": 13,
"O": 14,
"P": 15,
}
xlsx, err := excelize.OpenFile(excel_path)
if err != nil {
fmt.Println("open file err:", err)
}
sheetname := xlsx.GetSheetName(xlsx.GetActiveSheetIndex())
rows, _ := xlsx.GetRows(sheetname)
out := make([]string, 0)
for _, row := range rows {
for index, colCel := range row {
if index == colNum[col] {
out = append(out, colCel)
}
}
}
return out
}