【发布时间】:2020-09-26 14:07:29
【问题描述】:
我尝试使用https://github.com/tealeg/xlsx 和https://github.com/360EntSecGroup-Skylar/excelize 我成功读取了excel文件
package main
import (
"fmt"
"github.com/360EntSecGroup-Skylar/excelize"
)
func main() {
f, err := excelize.OpenFile("Book1.xlsx")
if err != nil {
fmt.Println(err)
return
}
// Get value from cell by given worksheet name and axis.
cell, err := f.GetCellValue("Sheet1", "B2")
if err != nil {
fmt.Println(err)
return
}
fmt.Println(cell)
// Get all the rows in the Sheet1.
rows, err := f.GetRows("Sheet1")
for _, row := range rows {
for _, colCell := range row {
fmt.Print(colCell, "\t")
}
fmt.Println()
}
}
把我想将数据从excel转换为定义结构的数组
例子
type InvoiceSheet struct {
amount string
item string
}
var invoices []InvoiceSheet
err := excel.READMETHOD('path of file', &invoices)
然后我可以迭代发票
【问题讨论】:
-
您好,我编辑了我的答案。祝你有美好的一天:)