Golang 导出Excel

2021-11-01 11:58:02 浏览数 (2)

package main

import ( "os" "encoding/csv" )

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

代码语言:javascript复制
f.WriteString("xEFxBBxBF") // 写入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()

} </pre>

0 人点赞