This repository has been archived by the owner on Dec 12, 2024. It is now read-only.
forked from tealeg/xlsx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stream_style.go
124 lines (100 loc) · 4.18 KB
/
stream_style.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
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
package xlsx
// StreamStyle has style and formatting information.
// Used to store a style for streaming
type StreamStyle struct {
xNumFmtId int
style *Style
}
const (
GeneralFormat = 0
IntegerFormat = 1
DecimalFormat = 2
DateFormat_dd_mm_yy = 14
DateTimeFormat_d_m_yy_h_mm = 22
)
var (
StreamStyleFromColumn StreamStyle
StreamStyleDefaultString StreamStyle
StreamStyleBoldString StreamStyle
StreamStyleItalicString StreamStyle
StreamStyleUnderlinedString StreamStyle
StreamStyleDefaultInteger StreamStyle
StreamStyleBoldInteger StreamStyle
StreamStyleItalicInteger StreamStyle
StreamStyleUnderlinedInteger StreamStyle
StreamStyleDefaultDate StreamStyle
StreamStyleDefaultDecimal StreamStyle
)
var (
FontBold *Font
FontItalic *Font
FontUnderlined *Font
)
var (
FillGreen *Fill
FillRed *Fill
FillWhite *Fill
)
func init() {
// Init Fonts
FontBold = DefaultFont()
FontBold.Bold = true
FontItalic = DefaultFont()
FontItalic.Italic = true
FontUnderlined = DefaultFont()
FontUnderlined.Underline = true
// Init Fills
FillGreen = NewFill(Solid_Cell_Fill, RGB_Light_Green, RGB_White)
FillRed = NewFill(Solid_Cell_Fill, RGB_Light_Red, RGB_White)
FillWhite = DefaultFill()
// Init default string styles
StreamStyleDefaultString = MakeStringStyle(DefaultFont(), DefaultFill(), DefaultAlignment(), DefaultBorder())
StreamStyleBoldString = MakeStringStyle(FontBold, DefaultFill(), DefaultAlignment(), DefaultBorder())
StreamStyleItalicString = MakeStringStyle(FontItalic, DefaultFill(), DefaultAlignment(), DefaultBorder())
StreamStyleUnderlinedString = MakeStringStyle(FontUnderlined, DefaultFill(), DefaultAlignment(), DefaultBorder())
// Init default Integer styles
StreamStyleDefaultInteger = MakeIntegerStyle(DefaultFont(), DefaultFill(), DefaultAlignment(), DefaultBorder())
StreamStyleBoldInteger = MakeIntegerStyle(FontBold, DefaultFill(), DefaultAlignment(), DefaultBorder())
StreamStyleItalicInteger = MakeIntegerStyle(FontItalic, DefaultFill(), DefaultAlignment(), DefaultBorder())
StreamStyleUnderlinedInteger = MakeIntegerStyle(FontUnderlined, DefaultFill(), DefaultAlignment(), DefaultBorder())
StreamStyleDefaultDate = MakeDateStyle(DefaultFont(), DefaultFill(), DefaultAlignment(), DefaultBorder())
StreamStyleDefaultDecimal = MakeDecimalStyle(DefaultFont(), DefaultFill(), DefaultAlignment(), DefaultBorder())
}
// MakeStyle creates a new StreamStyle and add it to the styles that will be streamed.
func MakeStyle(numFormatId int, font *Font, fill *Fill, alignment *Alignment, border *Border) StreamStyle {
newStyle := NewStyle()
newStyle.Font = *font
newStyle.Fill = *fill
newStyle.Alignment = *alignment
newStyle.Border = *border
newStyle.ApplyFont = true
newStyle.ApplyFill = true
newStyle.ApplyAlignment = true
newStyle.ApplyBorder = true
newStreamStyle := StreamStyle{
xNumFmtId: numFormatId,
style: newStyle,
}
return newStreamStyle
}
// MakeStringStyle creates a new style that can be used on cells with string data.
// If used on other data the formatting might be wrong.
func MakeStringStyle(font *Font, fill *Fill, alignment *Alignment, border *Border) StreamStyle {
return MakeStyle(GeneralFormat, font, fill, alignment, border)
}
// MakeIntegerStyle creates a new style that can be used on cells with integer data.
// If used on other data the formatting might be wrong.
func MakeIntegerStyle(font *Font, fill *Fill, alignment *Alignment, border *Border) StreamStyle {
return MakeStyle(IntegerFormat, font, fill, alignment, border)
}
// MakeDecimalStyle creates a new style that can be used on cells with decimal numeric data.
// If used on other data the formatting might be wrong.
func MakeDecimalStyle(font *Font, fill *Fill, alignment *Alignment, border *Border) StreamStyle {
return MakeStyle(DecimalFormat, font, fill, alignment, border)
}
// MakeDateStyle creates a new style that can be used on cells with Date data.
// The formatting used is: dd_mm_yy
// If used on other data the formatting might be wrong.
func MakeDateStyle(font *Font, fill *Fill, alignment *Alignment, border *Border) StreamStyle {
return MakeStyle(DateFormat_dd_mm_yy, font, fill, alignment, border)
}