import "github.com/tealeg/xlsx/v3"
func readXLSX() {
filename := "wd.xlsx"
xlFile, err := xlsx.OpenFile(filename)
if err != nil {
fmt.Println(err.Error())
return
}
// 遍历sheet页读取
for _, sheet := range xlFile.Sheets {
fmt.Println("sheet name: ", sheet.Name)
output := [][]string{}
err = sheet.ForEachRow(func(r *xlsx.Row) error {
cells := []string{}
err := r.ForEachCell(func(c *xlsx.Cell) error {
cells = append(cells, c.Value)
return nil
})
if err != nil {
return err
}
output = append(output, cells)
return nil
})
if err != nil {
fmt.Printf("sheet.ForEachRow err=%#v\n",err)
}
fmt.Printf("output===%#v\n",output)
for _,v := range output{
fmt.Printf("line=%#v\n",v)
}
}
fmt.Println("\n\nimport success")
}
推荐一个功能丰富、兼容性好、高性能的 Excel 文档基础库:[https://github.com/xuri/excelize](https://github.com/xuri/excelize)
#1