golang的XSLX文件读写库:XSLX
jopen
10年前
Google Go (golang)库用于读写XLSX文件。
xlsx这个库能够在Go程序中简化Microsoft Excel最新版本的XML格式的读与写操作。
读示例:
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()) } }