-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstyle.go
More file actions
151 lines (130 loc) · 3.67 KB
/
style.go
File metadata and controls
151 lines (130 loc) · 3.67 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
package gospreadsheet
// HorizontalAlignment represents horizontal text alignment.
type HorizontalAlignment string
const (
AlignLeft HorizontalAlignment = "left"
AlignCenter HorizontalAlignment = "center"
AlignRight HorizontalAlignment = "right"
AlignJustify HorizontalAlignment = "justify"
AlignGeneral HorizontalAlignment = "general"
)
// VerticalAlignment represents vertical text alignment.
type VerticalAlignment string
const (
AlignTop VerticalAlignment = "top"
AlignMiddle VerticalAlignment = "center"
AlignBottom VerticalAlignment = "bottom"
)
// BorderStyle represents a border line style.
type BorderStyle string
const (
BorderNone BorderStyle = "none"
BorderThin BorderStyle = "thin"
BorderMedium BorderStyle = "medium"
BorderThick BorderStyle = "thick"
BorderDashed BorderStyle = "dashed"
BorderDotted BorderStyle = "dotted"
BorderDouble BorderStyle = "double"
)
// Border represents a single border edge.
type Border struct {
Style BorderStyle
Color string // hex color, e.g., "FF0000"
}
// Borders represents all four borders of a cell.
type Borders struct {
Left Border
Right Border
Top Border
Bottom Border
Diagonal Border
DiagonalUp bool
DiagonalDown bool
}
// Font represents cell font properties.
type Font struct {
Name string
Size float64
Bold bool
Italic bool
Underline bool
Strikethrough bool
Color string // hex color
}
// Fill represents cell fill/background properties.
type Fill struct {
Type string // "solid", "pattern", "none"
Color string // hex color
Pattern string // pattern type for pattern fills
}
// Alignment represents cell text alignment.
type Alignment struct {
Horizontal HorizontalAlignment
Vertical VerticalAlignment
WrapText bool
ShrinkToFit bool
TextRotation int // degrees, -90 to 90
Indent int
}
// NumberFormat represents a cell number format.
type NumberFormat struct {
FormatCode string
}
// Common number format codes.
var (
FormatGeneral = NumberFormat{FormatCode: "General"}
FormatNumber = NumberFormat{FormatCode: "0"}
FormatNumber2Dec = NumberFormat{FormatCode: "0.00"}
FormatPercent = NumberFormat{FormatCode: "0%"}
FormatPercent2Dec = NumberFormat{FormatCode: "0.00%"}
FormatDate = NumberFormat{FormatCode: "yyyy-mm-dd"}
FormatDateTime = NumberFormat{FormatCode: "yyyy-mm-dd hh:mm:ss"}
FormatTime = NumberFormat{FormatCode: "hh:mm:ss"}
FormatCurrency = NumberFormat{FormatCode: `#,##0.00"$"`}
FormatAccounting = NumberFormat{FormatCode: `_("$"* #,##0.00_)`}
FormatText = NumberFormat{FormatCode: "@"}
)
// Style represents the complete style of a cell.
type Style struct {
Font *Font
Fill *Fill
Borders *Borders
Alignment *Alignment
NumberFormat *NumberFormat
}
// NewStyle creates a new empty style.
func NewStyle() *Style {
return &Style{}
}
// SetFont sets the font and returns the style for chaining.
func (s *Style) SetFont(f *Font) *Style {
s.Font = f
return s
}
// SetFill sets the fill and returns the style for chaining.
func (s *Style) SetFill(f *Fill) *Style {
s.Fill = f
return s
}
// SetBorders sets the borders and returns the style for chaining.
func (s *Style) SetBorders(b *Borders) *Style {
s.Borders = b
return s
}
// SetAlignment sets the alignment and returns the style for chaining.
func (s *Style) SetAlignment(a *Alignment) *Style {
s.Alignment = a
return s
}
// SetNumberFormat sets the number format and returns the style for chaining.
func (s *Style) SetNumberFormat(nf *NumberFormat) *Style {
s.NumberFormat = nf
return s
}
// DefaultFont returns the default font.
func DefaultFont() *Font {
return &Font{
Name: "Calibri",
Size: 11,
}
}