This repository has been archived by the owner on Jun 27, 2022. It is now read-only.
/
format.go
161 lines (118 loc) · 3.91 KB
/
format.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
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
152
153
154
155
156
157
158
159
160
161
package goxlsxwriter
/*
#cgo LDFLAGS: -L. -lxlsxwriter
#include <xlsxwriter.h>
*/
import "C"
import "unsafe"
// UNDERLINE_* constants are to be used with SetUnderline().
const (
// Single underline.
UNDERLINE_SINGLE int = C.LXW_UNDERLINE_SINGLE
// Double underline.
UNDERLINE_DOUBLE int = C.LXW_UNDERLINE_DOUBLE
// Single accounting underline.
UNDERLINE_SINGLE_ACCOUNTING int = C.LXW_UNDERLINE_SINGLE_ACCOUNTING
// Double accounting line.
UNDERLINE_DOUBLE_ACCOUNTING int = C.LXW_UNDERLINE_DOUBLE_ACCOUNTING
)
// PATTERN_* constants are to be used with SetPattern().
const (
// Solid.
PATTERN_SOLID int = C.LXW_PATTERN_SOLID
// Medium gray.
PATTERN_MEDIUM_GRAY int = C.LXW_PATTERN_MEDIUM_GRAY
// Dark gray.
PATTERN_DARK_GRAY int = C.LXW_PATTERN_DARK_GRAY
// Light gray.
PATTERN_LIGHT_GRAY int = C.LXW_PATTERN_LIGHT_GRAY
// Dark horizontal line.
PATTERN_DARK_HORIZONTAL int = C.LXW_PATTERN_DARK_HORIZONTAL
// Dark vertical line.
PATTERN_DARK_VERTICAL int = C.LXW_PATTERN_DARK_VERTICAL
// Dark diagonal stripe.
PATTERN_DARK_DOWN int = C.LXW_PATTERN_DARK_DOWN
// Reverse dark diagonal stripe.
PATTERN_DARK_UP int = C.LXW_PATTERN_DARK_UP
// Dark grid.
PATTERN_DARK_GRID int = C.LXW_PATTERN_DARK_GRID
// Dark trellis.
PATTERN_DARK_TRELLIS int = C.LXW_PATTERN_DARK_TRELLIS
// Light horizontal line.
PATTERN_LIGHT_HORIZONTAL int = C.LXW_PATTERN_LIGHT_HORIZONTAL
// Light vertical line.
PATTERN_LIGHT_VERTICAL int = C.LXW_PATTERN_LIGHT_VERTICAL
// Light diagonal stripe.
PATTERN_LIGHT_DOWN int = C.LXW_PATTERN_LIGHT_DOWN
// Reverse light diagonal stripe.
PATTERN_LIGHT_UP int = C.LXW_PATTERN_LIGHT_UP
// Light grid.
PATTERN_LIGHT_GRID int = C.LXW_PATTERN_LIGHT_GRID
// Light trellis.
PATTERN_LIGHT_TRELLIS int = C.LXW_PATTERN_LIGHT_TRELLIS
// 12.5% gray.
PATTERN_GRAY_125 int = C.LXW_PATTERN_GRAY_125
// 6.25% gray.
PATTERN_GRAY_0625 int = C.LXW_PATTERN_GRAY_0625
)
// Format represents an Excel style used to apply formatting to cells.
type Format struct {
CFormat *C.struct_lxw_format
}
// NewFormat creates and returns a new instance of Format.
func NewFormat(workbook *Workbook) *Format {
cFormat := C.workbook_add_format(workbook.CWorkbook)
format := &Format{
CFormat: cFormat,
}
return format
}
// SetFontName sets the format's font face.
func (f *Format) SetFontName(fontName string) {
cFontName := C.CString(fontName)
defer C.free(unsafe.Pointer(cFontName))
C.format_set_font_name(f.CFormat, cFontName)
}
// SetFontSize sets the font size.
func (f *Format) SetFontSize(size int) {
cSize := (C.double)(size)
C.format_set_font_size(f.CFormat, cSize)
}
// SetFontColor sets the font color.
func (f *Format) SetFontColor(color int) {
cColor := (C.lxw_color_t)(color)
C.format_set_font_color(f.CFormat, cColor)
}
// SetBold sets the font to be bold.
func (f *Format) SetBold() {
C.format_set_bold(f.CFormat)
}
// SetItalic sets the font to be italic.
func (f *Format) SetItalic() {
C.format_set_italic(f.CFormat)
}
// SetUnderline sets the font to be underline using the
// specified UNDERLINE_* style.
func (f *Format) SetUnderline(style int) {
cStyle := (C.uint8_t)(style)
C.format_set_underline(f.CFormat, cStyle)
}
// SetPattern sets the pattern to the specific PATTERN_* pattern.
func (f *Format) SetPattern(pattern int) {
cPattern := (C.uint8_t)(pattern)
C.format_set_pattern(f.CFormat, cPattern)
}
// SetBackgroundColor sets the background color.
func (f *Format) SetBackgroundColor(color int) {
cColor := (C.lxw_color_t)(color)
C.format_set_bg_color(f.CFormat, cColor)
}
// SetNumericalFormat sets the numerical format.
// It controls whether a number is displayed as an integer,
// a floating point number, a date, a currency value or some other
// user defined format (e.g., "d mmm yyyy").
func (f *Format) SetNumericalFormat(numberFormat string) {
cNumberFormat := C.CString(numberFormat)
defer C.free(unsafe.Pointer(cNumberFormat))
C.format_set_num_format(f.CFormat, cNumberFormat)
}