写入 `csv` 文件编码头标识格式以避免中文乱码

This commit is contained in:
千橘 雫霞 2023-01-19 18:11:55 +08:00
parent c54fb92537
commit d2eb422d86
No known key found for this signature in database
GPG Key ID: 8C478C263854EFAA
1 changed files with 2 additions and 1 deletions

View File

@ -75,7 +75,8 @@ func ExportCsv(data []CloudflareIPData) {
return
}
defer fp.Close()
w := csv.NewWriter(fp) //创建一个新的写入文件流
_, _ = fp.Write([]byte{0xef, 0xbb, 0xbf}) // UTF-8 BOM 头
w := csv.NewWriter(fp) // 创建一个新的写入文件流
_ = w.Write([]string{"IP 地址", "已发送", "已接收", "丢包率", "平均延迟", "下载速度 (MB/s)"})
_ = w.WriteAll(convertToString(data))
w.Flush()