https://github.com/freefishgo/goexcel
An array to Excel conversion and Excel to array conversion
https://github.com/freefishgo/goexcel
excel exceltolist go golang listtoexcel openxml
Last synced: about 1 month ago
JSON representation
An array to Excel conversion and Excel to array conversion
- Host: GitHub
- URL: https://github.com/freefishgo/goexcel
- Owner: freefishgo
- License: mit
- Created: 2021-08-13T05:11:58.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-04-09T11:48:49.000Z (almost 2 years ago)
- Last Synced: 2024-06-20T15:48:35.528Z (over 1 year ago)
- Topics: excel, exceltolist, go, golang, listtoexcel, openxml
- Language: Go
- Homepage:
- Size: 41 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# goexcel
excel
``` go
type s1 struct {
Name string `export:"一级姓名|姓名2,3"`
Age int32 `export:"年龄2,6"`
Time string `export:"时间2,9"`
}
type s struct {
Name string `export:"一级姓名|姓名1,2"`
Age int32 `export:"年龄1,5"`
Time string `export:"时间1,8"`
List []s1
}
type p struct {
Name string `export:"一级姓名|二级姓名|姓名,1"`
Age int32 `export:"年龄,4"`
Time string `export:"时间,7"`
List []s
}
func main() {
v := &p{
Name: "天外飞仙",
Age: 18,
Time: "我是时间",
List: []s{
{
Name: "大名",
Age: 19,
Time: "我是大名时间",
List: []s1{
{
Name: "大名",
Age: 19,
Time: "我是大名时间",
},
},
},
{
Name: "小名",
Age: 20,
},
},
}
v2:=&p{
Name: "天外飞仙",
Age: 16,
Time: "我是开始时间",
List: []s{
{
Name: "小名",
Age: 20,
Time: "我是小名时间",
List: []s1{
{
Name: "大名",
Age: 19,
Time: "我是大名时间",
},
{
Name: "大名",
Age: 19,
Time: "我是大名时间",
},
},
},
{
Name: "小名",
Age: 21,
Time: "我是小名名时间2",
},
{
Name: "小名",
Age: 21,
Time: "我是小名名时间2",
},
},
}
list := append([]*p(nil), v, v2)
xlsx, err := goexcel.ListToExcelSheet1(list)
if err != nil {
fmt.Println(err.Error())
return
}
err = xlsx.SaveAs(time.Now().Format("20060102150405") + ".xlsx")
}
```
一级姓名
年龄
年龄1
年龄2
时间
时间1
时间2
二级姓名
姓名1
姓名2
姓名
天外飞仙
大名
大名
18
19
19
我是时间
我是大名时间
我是大名时间
小名
20
天外飞仙
小名
大名
16
20
19
我是开始时间
我是小名时间
我是大名时间
大名
19
我是大名时间
小名
21
我是小名名时间2
小名
21
我是小名名时间2
``` go
// load from excel
var list []*p
goexcel.ExcelSheet1ToListFromPath("20210814182854.xlsx", &list)
```