https://github.com/9d4/ekelesek
Wrapper around excelize
https://github.com/9d4/ekelesek
Last synced: about 1 year ago
JSON representation
Wrapper around excelize
- Host: GitHub
- URL: https://github.com/9d4/ekelesek
- Owner: 9d4
- License: gpl-3.0
- Created: 2023-07-27T14:12:52.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-09-21T03:36:03.000Z (over 2 years ago)
- Last Synced: 2025-01-29T22:46:14.550Z (over 1 year ago)
- Language: Go
- Size: 122 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ekelesek
Extract xlsx to struct with [excelize](github.com/xuri/excelize).
## Usage
| Age | Name | Birth Day |
| --- | -------------- | --------- |
| 26 | Kaye Goff | April |
| 22 | Adrienne Kirby | May |
| 27 | John | May |
Make new type struct.
```go
type Student struct {
Name string `lookup:"name"`
Age int `lookup:"age"`
BirthDay string `lookup:"birthday"`
}
```
Map the xlsx column.
```go
var lookupMap = map[string]string{
"Name": "name",
"Age": "age",
"Birth Day": "birthday",
}
```
The key is the column name in the table and the value is the lookup key for Student struct.
Full example see in example directory or below code.
```go
package main
import (
"fmt"
"github.com/9d4/ekelesek/eksel"
"github.com/xuri/excelize/v2"
)
var lookupMap = map[string]string{
"Name": "name",
"Age": "age",
"Birth Day": "birthday",
}
type Student struct {
Name string `lookup:"name"`
Age int `lookup:"age"`
BirthDay string `lookup:"birthday"`
}
func main() {
f, _ := excelize.OpenFile("./data.xlsx")
rows, _ := f.Rows("Sheet1")
var students []Student
eksel.Parse(rows, lookupMap, &students)
for _, student := range students {
fmt.Printf("Name: %s\nAge: %d\nBirthday: %s\n\n", student.Name, student.Age, student.BirthDay)
}
}
```
### Supported type
- Int
- Float
- Uint
- Bool
- Time
> Note: The code is not well tested, I only use this for string, int, and datetime type.