Ai
16 Star 69 Fork 54

ShirDon-廖显东/Go语言高级开发与实战-随书代码

Create your Gitee Account
Explore and code with more than 13.5 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
1.2.7-csv.go 1022 Bytes
Copy Edit Raw Blame History
ShirDon-廖显东 authored 2021-12-28 09:45 +08:00 . commit
//++++++++++++++++++++++++++++++++++++++++
// 《Go语言高级开发与实战》源码
//++++++++++++++++++++++++++++++++++++++++
// Author:廖显东(ShirDon)
// Blog:https://www.shirdon.com/
// 知乎:https://www.zhihu.com/people/shirdonl
// 公众号:源码大数据
// 仓库地址:https://gitee.com/shirdonl/goAdvanced
// 仓库地址:https://github.com/shirdonl/goAdvanced
//++++++++++++++++++++++++++++++++++++++++
package main
import (
"encoding/csv"
"os"
)
func main() {
//创建一个名为"test.csv"的文件
f, err := os.Create("test.csv")
if err != nil {
panic(err)
}
defer f.Close()
f.WriteString("\xEF\xBB\xBF") // 写入UTF-8 BOM
//NewWriter()函数返回一个Writer对象
w := csv.NewWriter(f)
//调用Writer对象的Write()方法写入数据到CSV文件
w.Write([]string{"学号", "姓名", "分数"})
w.Write([]string{"1", "Barry", "99.5"})
w.Write([]string{"2", "Shirdon", "100"})
w.Write([]string{"3", "Jack", "88"})
w.Write([]string{"4", "Dong", "68"})
w.Flush()
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/shirdonl/goAdvanced.git
git@gitee.com:shirdonl/goAdvanced.git
shirdonl
goAdvanced
Go语言高级开发与实战-随书代码
0f051d9f4e35

Search