golang中的excel上传,读取数据

package test

import "github.com/plandem/xlsx"

//学生结构体 type Stu struct { Name string Age string }
//读取表中数据,返回list func RedExcel()([]Stu) { filePath :="./test.xlsx" list := make([]Stu,0) //定义表头映射的字段数组 head:=[]string{"name","age"} xl, err := xlsx.Open(filePath) if err != nil { fmt.Print("err") return list } defer xl.Close() sheet := xl.Sheet(0, xlsx.SheetModeStream) totalCols, totalRows := sheet.Dimension() for row := 1; row < totalRows; row++ { stu := Stu{ Name: "", Age: "", } for col := 0; col < totalCols; col++ { value := sheet.Cell(col, row).String() field :=head[col] switch field { case "name": stu.Name=value case "age": stu.Age=value } } list=append(list,stu) } return list }

 

golang中的excel上传,读取数据

上一篇:利用 JS 脚本实现网页全自动秒杀抢购


下一篇:年轻代频繁ParNew GC,导致http服务rt飙高