-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsheet.go
74 lines (61 loc) · 1.79 KB
/
sheet.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package excelsior
import "github.com/xuri/excelize/v2"
// SheetProvider is the interface for the Excel sheet.
type SheetProvider interface {
SheetBase
SheetData
}
// Row represents Excel row.
type Row []any
// GetStyleByColIDFn is signature function for get the style by providing column number.
type GetStyleByColIDFn func(colID int) int
// SheetBase is the interface generated by excelsior.Sheet, reducing the boiler-plates.
type SheetBase interface {
TotalColumn() int
HeaderRow() Row
HeaderRowStyle() GetStyleByColIDFn
RowStyle() GetStyleByColIDFn
}
// SheetData is the interface need to be provided by the user of excelsior.
type SheetData interface {
Total() int // total data
Row(i int) Row //
}
// Sheet implements SheetProvider interface.
type Sheet struct {
SheetData
headerRow Row
rowGetStyleFn GetStyleByColIDFn
headStyleID int
}
// NewSheet will create new Sheet.
func NewSheet(headerRow Row, rowGetStyleFn GetStyleByColIDFn, headStyleID int, data SheetData) *Sheet {
return &Sheet{
SheetData: data,
headerRow: headerRow,
rowGetStyleFn: rowGetStyleFn,
headStyleID: headStyleID,
}
}
// HeaderRow returns rows for header.
func (s Sheet) HeaderRow() Row {
return s.headerRow
}
// TotalColumn returns total column.
func (s Sheet) TotalColumn() int {
return len(s.headerRow)
}
// HeaderRowStyle returns the style rowSetter for the header row.
func (s Sheet) HeaderRowStyle() GetStyleByColIDFn {
return func(_ int) int {
return s.headStyleID
}
}
// RowStyle returns the style rowSetter for the remaining row.
func (s Sheet) RowStyle() GetStyleByColIDFn {
return s.rowGetStyleFn
}
// Generate creates Excel sheet with provided excelize.File, and sheet name.
func (s Sheet) Generate(file *excelize.File, name string) error {
return GenerateSheet(file, name, s)
}