Skip to content

Instantly share code, notes, and snippets.

@paulyung541
Created March 4, 2020 06:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paulyung541/1807ba552495f48790f6e6379c75573d to your computer and use it in GitHub Desktop.
Save paulyung541/1807ba552495f48790f6e6379c75573d to your computer and use it in GitHub Desktop.
go: excel操作
import (
"fmt"
"github.com/tealeg/xlsx"
)
func main() {
test()
}
var header = []string{
"日期",
"姓名",
"联系电话",
"所需药品",
}
func test() {
var (
file *xlsx.File
sheet *xlsx.Sheet
err error
)
file = xlsx.NewFile()
sheet, err = file.AddSheet("Sheet1")
if err != nil {
fmt.Printf(err.Error())
}
row := sheet.AddRow()
for _, head := range header {
row.AddCell().Value = head
}
row1 := sheet.AddRow()
row1.AddCell().Value = "2006-01-01"
row1.AddCell().Value = "小明"
row1.AddCell().Value = "13903039293"
row1.AddCell().Value = "板蓝根"
err = file.Save("MyXLSXFile.xlsx")
if err != nil {
fmt.Printf(err.Error())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment