Skip to content

Commit 11c5c9c

Browse files
committed
docs: update readme
1 parent 4fd0ab2 commit 11c5c9c

File tree

3 files changed

+30
-28
lines changed

3 files changed

+30
-28
lines changed

foo.xlsx

5.1 KB
Binary file not shown.

readme.md

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,49 +9,51 @@ a easier use excel file create tool for golang
99
## Quick Start
1010
* define a struct with excel_header tag and implement `SheetName` method
1111
```go
12-
type User struct {
13-
Name string `excel_header:"姓名"`
14-
Age int `excel_header:"年龄"`
15-
Birthday time.Time `excel_header:"生日"`
16-
Jobs *string `excel_header:"工作"`
12+
type Foo struct {
13+
ID int64 `excel_header:"id"`
14+
Name string `excel_header:"name"`
15+
CreatedAt time.Time `excel_header:"created_at"`
16+
DeletedAt *time.Time `excel_header:"deleted_at"`
1717
}
18-
func (u User) SheetName() string {
19-
return "用户信息"
18+
func (u Foo) SheetName() string {
19+
return "foo sheet name"
2020
}
2121
```
2222

2323
* construct some data
2424
```go
25-
user1 := User{
26-
Name: "张三",
27-
Age: 18,
28-
Birthday: time.Now(),
29-
Jobs: nil,
25+
bar1DeletedAt := time.Date(2024, 1, 3, 15, 4, 5, 0, time.Local)
26+
sheetModels := []excelorm.SheetModel{
27+
Foo{
28+
ID: 1,
29+
Name: "Bar1",
30+
CreatedAt: time.Date(2024, 1, 2, 15, 4, 5, 0, time.Local),
31+
DeletedAt: &bar1DeletedAt,
32+
},
33+
Foo{
34+
ID: 2,
35+
Name: "Bar2",
36+
CreatedAt: time.Date(2024, 1, 2, 15, 4, 5, 0, time.Local),
37+
},
3038
}
31-
user2 := User{
32-
Name: "李四",
33-
Age: 20,
34-
Birthday: time.Now(),
35-
Jobs: toPtr("程序员"),
36-
}
37-
sheetModels := make([]excelorm.SheetModel, 0)
38-
sheetModels = append(sheetModels, user1, user2)
3939
```
4040
* write to excel file
4141
```go
42-
err := excelorm.WriteExcelSaveAs("test.xlsx", sheetModels)
43-
if err != nil {
44-
panic(err)
42+
if err := excelorm.WriteExcelSaveAs("foo.xlsx", sheetModels,
43+
excelorm.WithTimeFormatLayout("2006/01/02 15:04:05"),
44+
excelorm.WithIfNullValue("-"),
45+
); err != nil {
46+
log.Fatal(err)
4547
}
4648
```
4749
* you can see the result in the file<br>
4850

49-
| 姓名 | 年龄 | 生日 | 工作 |
50-
|----|----|---------------------|-----|
51-
| 张三 | 18 | 2021-08-08 16:00:00 | |
52-
| 李四 | 20 | 2021-08-08 16:00:00 | 程序员 |
51+
| id | name | created_at | deleted_at |
52+
|----|------|---------------------|---------------------|
53+
| 1 | Bar1 | 2024/01/02 15:04:05 | 2024/01/03 15:04:05 |
54+
| 2 | Bar2 | 2024/01/02 15:04:05 | - |
5355

5456

55-
[test.xlsx](test.xlsx)
57+
[foo.xlsx](foo.xlsx)
5658

5759
* support multi-sheets by define more structs

test.xlsx

-6.14 KB
Binary file not shown.

0 commit comments

Comments
 (0)