0
点赞
收藏
分享

微信扫一扫

IPsec-Vpn

霸姨 2024-09-24 阅读 41

一、安装依赖

go get github.com/tealeg/xlsx

二、main.go

package main

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

type Student struct {
	Name string
	Sex  string
}

func (student Student) show() {
	fmt.Printf("Name:%s Sex:%s\r\n", student.Name, student.Sex)
}

func main() {
	excelPath := "students.xlsx"
	xlFile, err := xlsx.OpenFile(excelPath)
	if err != nil {
		fmt.Printf("Error opening Excel file: %s\n", err)
		return
	}
	sheet := xlFile.Sheets[0]
	var students []Student
	i := 0
	for _, row := range sheet.Rows {
		name := row.Cells[0].String()
		sex := row.Cells[1].String()
		fmt.Printf("name:%s sex:%s \r\n", name, sex)
		students = append(students, Student{Name: name, Sex: sex})
		i++
	}
	for _, student := range students {
		student.show()
	}
}

输出:

 

举报

相关推荐

0 条评论