Go生成csv文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package main
import (
"encoding/csv"
"os"
)

func main() {
f, err := os.Create("test.csv")
if err != nil {
panic(err)
}
defer f.Close()

w := csv.NewWriter(f)
data := [][]string{
{"1", "11", "11"},
{"2", "22", "22"}
}
w.WriteAll(data)
w.Flush()
}