go生成excel
package main import ( "fmt" "github.com/tealeg/xlsx" ) type Try struct { I string J string K string } func main() { var file *xlsx.File var sheet *xlsx.Sheet var row *xlsx.Row var err error file = xlsx.NewFile() sheet, err = file.AddSheet("Sheet1") if err != nil { fmt.Println(err.Error()) } //添加表 A := Try{ I: "第一列", J: "第二列", K: "第三列", } row = sheet.AddRow() row.WriteStruct(&A, 3) B := Try{ I: "1", J: "2", K: "3", } row = sheet.AddRow() row.WriteStruct(&B, 3) C := Try{ I: "11", J: "22", K: "33", } row = sheet.AddRow() row.WriteStruct(&C, 3) err = file.Save("MyXLSXFile.xlsx") if err != nil { fmt.Println(err.Error()) } }