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")
}
有疑问加站长微信联系(非本文作者)