GOLANG输出CSV文件

前端之家收集整理的这篇文章主要介绍了GOLANG输出CSV文件前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
packagemain

import(
"os"
"encoding/csv"
)

funcmain(){
f,err:=os.Create("haha2.csv")
iferr!=nil{
panic(err)
}
deferf.Close()

f.WriteString("\xEF\xBB\xBF")//写入UTF-8BOM

w:=csv.NewWriter(f)
w.Write([]string{"编号","姓名","年龄"})
w.Write([]string{"1","张三","23"})
w.Write([]string{"2","李四","24"})
w.Write([]string{"3","王五","25"})
w.Write([]string{"4","赵六","26"})
w.Flush()
}
原文链接:https://www.f2er.com/go/191041.html

猜你在找的Go相关文章