csvFile, _ := os.Open("file.csv")
reader := csv.NewReader(csvFile)
records, err := reader.ReadAll()
if err != nil {
fmt.Println("无法读取:", err)
return
}
报错如下:
golang csv parse error on line 1, column 1: bare " in non-quoted-field
由于再window下会有格式问题,添加两行代码可解决
csvFile, _ := os.Open("file.csv")
reader := csv.NewReader(csvFile)
reader.Comma = ',' //添加
reader.LazyQuotes = true //添加
records, err := reader.ReadAll()
if err != nil {
fmt.Println("无法读取:", err)
return
}