Go語言導(dǎo)出內(nèi)容到Excel的方法
更新時間:2015年02月23日 11:17:14 作者:不吃皮蛋
這篇文章主要介紹了Go語言導(dǎo)出內(nèi)容到Excel的方法,涉及Go語言操作excel的技巧,具有一定參考借鑒價值,需要的朋友可以參考下
本文實例講述了Go語言導(dǎo)出內(nèi)容到Excel的方法。分享給大家供大家參考。具體實現(xiàn)方法如下:
復(fù)制代碼 代碼如下:
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語言程序設(shè)計有所幫助。
相關(guān)文章
Go處理json數(shù)據(jù)方法詳解(Marshal,UnMarshal)
這篇文章主要介紹了Go處理json數(shù)據(jù)的方法詳解,Marshal(),UnMarshal(),需要的朋友可以參考下2022-04-04
在Mac中搭建go語言開發(fā)環(huán)境的操作步驟
go語言在開發(fā)效率和運行效率中的優(yōu)勢讓很多人青睞,所以有傾向打算轉(zhuǎn)向go語言的開發(fā)。下面介紹在Mac中g(shù)olang的開發(fā)環(huán)境配置。有需要的可以參考借鑒。2016-08-08
詳解Go語言如何使用標(biāo)準(zhǔn)庫sort對切片進行排序
Sort?標(biāo)準(zhǔn)庫提供了對基本數(shù)據(jù)類型的切片和自定義類型的切片進行排序的函數(shù)。今天主要分享的內(nèi)容是使用?Go?標(biāo)準(zhǔn)庫?sort?對切片進行排序,感興趣的可以了解一下2022-12-12

