这是一个 Go 语言用来读写新的 Excel 文件格式 —— XSLX 的开发包。
读示例:
package main import ( "fmt" "github.com/tealeg/xlsx" ) func main() { excelFileName := "/home/tealeg/foo.xlsx" xlFile, err := xlsx.OpenFile(excelFileName) if err != nil { ... } for _, sheet := range xlFile.Sheets { for _, row := range sheet.Rows { for _, cell := range row.Cells { fmt.Printf("%s\n", cell.String()) } } } }
写示例:
package main import ( "fmt" "github.com/tealeg/xlsx" ) func main() { var file *xlsx.File var sheet *xlsx.Sheet var row *xlsx.Row var cell *xlsx.Cell var err error file = xlsx.NewFile() sheet = file.AddSheet("Sheet1") row = sheet.AddRow() cell = row.AddCell() cell.Value = "I am a cell!" err = file.Save("MyXLSXFile.xlsx") if err != nil { fmt.Printf(err.Error()) } }