Skip to content

A easier use excel file create tool for golang. 📄

License

Notifications You must be signed in to change notification settings

VarusHsu/excelorm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

excelorm

A easier use excel file create tool for golang

install

 go get -u 'github.com/varushsu/excelorm@latest'

Quick Start

  • define a struct with excel_header tag and implement SheetName method
type Foo struct {
    ID        int64      `excel_header:"id"`
    Name      string     `excel_header:"name"`
    CreatedAt time.Time  `excel_header:"created_at"`
    DeletedAt *time.Time `excel_header:"deleted_at"`
}
func (u Foo) SheetName() string {
    return "foo sheet name"
}
  • construct some data
bar1DeletedAt := time.Date(2024, 1, 3, 15, 4, 5, 0, time.Local)
sheetModels := []excelorm.SheetModel{
    Foo{
        ID:        1,
        Name:      "Bar1",
        CreatedAt: time.Date(2024, 1, 2, 15, 4, 5, 0, time.Local),
        DeletedAt: &bar1DeletedAt,
    },
    Foo{
        ID:        2,
        Name:      "Bar2",
        CreatedAt: time.Date(2024, 1, 2, 15, 4, 5, 0, time.Local),
    },
}
  • write to excel file
if err := excelorm.WriteExcelSaveAs("foo.xlsx", sheetModels,
    excelorm.WithTimeFormatLayout("2006/01/02 15:04:05"),
    excelorm.WithIfNullValue("-"), 
); err != nil {
    log.Fatal(err)
}
  • you can see the result in the file
id name created_at deleted_at
1 Bar1 2024/01/02 15:04:05 2024/01/03 15:04:05
2 Bar2 2024/01/02 15:04:05 -

foo.xlsx

  • support multi-sheets by define more structs

About

A easier use excel file create tool for golang. 📄

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages