Go language library for reading and writing Microsoft Excel™ (XLAM / XLSM / XLSX / XLTM / XLTX) spreadsheets
译文 用于读写Microsoft Excel电子表格的Go语言库 (XLAM/XLSM/XLSX/XLTM/XLTX)
文档
- 官网 https://xuri.me/excelize/
- github https://github.com/qax-os/excelize
- 中文文档 https://xuri.me/excelize/zh-hans/
- pkg.go https://pkg.go.dev/github.com/xuri/excelize/v2
安装
go get github.com/xuri/excelize/v2
示例
package main
import (
"github.com/xuri/excelize/v2"
)
func main() {
// 创建excel文件
file := excelize.NewFile()
// 获取第一个sheet
list := file.GetSheetList()
sheet := list[0]
// 设置单元格的值
file.SetCellValue(sheet, "A1", "Hello world.")
file.SetCellValue(sheet, "A2", 100)
// 保存文件
file.SaveAs("book.xlsx")
// 关闭文件
file.Close()
}