最近要用golang操作excel,故来玩下:
库地址:
https://github.com/360EntSecGroup-Skylar/excelize
示例代码如下:
package main
import (
"fmt"
"github.com/360EntSecGroup-Skylar/excelize"
)
func main() {
f, err := excelize.OpenFile("/xxxxxx/test.xlsx")
if err != nil {
fmt.Println(err)
return
}
// Get value from cell by given worksheet name and axis.
cell, err := f.GetCellValue("工作表1", "B2")
if err != nil {
fmt.Println(err)
return
}
fmt.Println(cell)
// Get all the rows in the Sheet1.
rows, err := f.GetRows("工作表1")
for i, row := range rows {
for j, colCell := range row {
fmt.Println(colCell, "---", i, j)
}
fmt.Println("")
}
}
结果:
go xxx
hello --- 0 0
helloxxx --- 0 1
helloyyy --- 0 2
end a --- 0 3
good --- 1 0
go xxx --- 1 1
go zzz --- 1 2
--- 1 3
excel中的内容为:
不多说。