Go语言导出内容到Excel的方法
时间:2021-02-23 15:14:40|栏目:Golang|点击: 次
本文实例讲述了Go语言导出内容到Excel的方法。分享给大家供大家参考。具体实现方法如下:
复制代码 代码如下:
package main
import (
"os"
"encoding/csv"
)
func main() {
f, err := os.Create("haha2.xls")
if err != nil {
panic(err)
}
defer f.Close()
f.WriteString("\xEF\xBB\xBF") // 写入UTF-8 BOM
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()
}
import (
"os"
"encoding/csv"
)
func main() {
f, err := os.Create("haha2.xls")
if err != nil {
panic(err)
}
defer f.Close()
f.WriteString("\xEF\xBB\xBF") // 写入UTF-8 BOM
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()
}
希望本文所述对大家的Go语言程序设计有所帮助。
上一篇:Go语言中io.Reader和io.Writer的详解与实现
栏 目:Golang
本文标题:Go语言导出内容到Excel的方法
本文地址:http://www.codeinn.net/misctech/68257.html