Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/kakilangit/excelsior

An excelize wrapper to separate the presentation and business logic
https://github.com/kakilangit/excelsior

excel excelize go

Last synced: 21 days ago
JSON representation

An excelize wrapper to separate the presentation and business logic

Awesome Lists containing this project

README

        

[github](https://github.com/kakilangit/excelsior)
[pkg.go.dev](https://pkg.go.dev/github.com/kakilangit/excelsior)

![Dall-E generated exelsior image](https://raw.githubusercontent.com/kakilangit/static/main/excelsior/excelsior.png)

# Excelsior

An excelize wrapper to separate the presentation and business logic.

```shell

go get -u -v github.com/kakilangit/excelsior

```

Example:

```go
package main

import (
"log"
"os"

"github.com/kakilangit/excelsior"
"github.com/xuri/excelize/v2"
)

// notFound implements excelsior.SheetData.
type notFound []string

// Total return total data.
func (f notFound) Total() int {
return len(f)
}

// Row represents excel row.
func (f notFound) Row(i int) excelsior.Row {
return []any{f[i]}
}

func main() {
data, err := excelsior.Serialize(func(file *excelize.File, style excelsior.Style) ([]byte, error) {
const sheetName = "not found alphabet"

excelsior.SetDefaultSheetName(file, sheetName)

headers := []any{"alphabet"}
rows := []string{"a", "b", "c"}

sheet := excelsior.NewSheet(headers, excelsior.DefaultGetStyleFn, style.Header(), notFound(rows))
if err := sheet.Generate(file, sheetName); err != nil {
return nil, err
}

return excelsior.Byte(file)
})
if err != nil {
log.Fatal(err)
}

f, err := os.Create("alphabet.xlsx")
if err != nil {
log.Fatal(err)
}
defer func() { _ = f.Close() }()

if _, err := f.Write(data); err != nil {
log.Fatal(err)
}

if err := f.Sync(); err != nil {
log.Fatal(err)
}
}

```

## License

MIT
Copyright (c) 2022 kakilangit