编写读取代码并准备好测试文件test.xlsx
  • excel.go
package main

import (
	"fmt"
	"github.com/tealeg/xlsx"
)

func main() {
	// 打开excel
	excelFile, err := xlsx.OpenFile("test.xlsx")
	if err != nil {
		panic(err)
	}

	// 从第一个sheet中读取数据
	sheet := excelFile.Sheets[0]
	for rowIndex, row := range sheet.Rows {
		for colIndex, cell := range row.Cells {
			value := cell.String()
			 
			fmt.Printf("%d - %d - %s\t",rowIndex,colIndex, value)
		}
		fmt.Printf("\n")
	}
}

初始并安装依赖(需要科学上网访问github)
go mod init excel

go get github.com/tealeg/xlsx

go run excel.go

golang-excel golang-excel


赞赏(Donation)
微信(Wechat Pay)

donation-wechatpay