1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Box\Spout\Writer\Common\Creator\Style; |
4
|
|
|
|
5
|
|
|
use Box\Spout\Common\Entity\Style\Border; |
6
|
|
|
use Box\Spout\Common\Entity\Style\CellAlignment; |
7
|
|
|
use Box\Spout\Common\Entity\Style\Style; |
8
|
|
|
use Box\Spout\Common\Exception\InvalidArgumentException; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class StyleBuilder |
12
|
|
|
* Builder to create new styles |
13
|
|
|
*/ |
14
|
|
|
class StyleBuilder |
15
|
|
|
{ |
16
|
|
|
/** @var Style Style to be created */ |
17
|
|
|
protected $style; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* |
21
|
|
|
*/ |
22
|
111 |
|
public function __construct() |
23
|
|
|
{ |
24
|
111 |
|
$this->style = new Style(); |
25
|
111 |
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Makes the font bold. |
29
|
|
|
* |
30
|
|
|
* @return StyleBuilder |
31
|
|
|
*/ |
32
|
20 |
|
public function setFontBold() |
33
|
|
|
{ |
34
|
20 |
|
$this->style->setFontBold(); |
35
|
|
|
|
36
|
20 |
|
return $this; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Makes the font italic. |
41
|
|
|
* |
42
|
|
|
* @return StyleBuilder |
43
|
|
|
*/ |
44
|
7 |
|
public function setFontItalic() |
45
|
|
|
{ |
46
|
7 |
|
$this->style->setFontItalic(); |
47
|
|
|
|
48
|
7 |
|
return $this; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Makes the font underlined. |
53
|
|
|
* |
54
|
|
|
* @return StyleBuilder |
55
|
|
|
*/ |
56
|
7 |
|
public function setFontUnderline() |
57
|
|
|
{ |
58
|
7 |
|
$this->style->setFontUnderline(); |
59
|
|
|
|
60
|
7 |
|
return $this; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Makes the font struck through. |
65
|
|
|
* |
66
|
|
|
* @return StyleBuilder |
67
|
|
|
*/ |
68
|
4 |
|
public function setFontStrikethrough() |
69
|
|
|
{ |
70
|
4 |
|
$this->style->setFontStrikethrough(); |
71
|
|
|
|
72
|
4 |
|
return $this; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Sets the font size. |
77
|
|
|
* |
78
|
|
|
* @param int $fontSize Font size, in pixels |
79
|
|
|
* @return StyleBuilder |
80
|
|
|
*/ |
81
|
53 |
|
public function setFontSize($fontSize) |
82
|
|
|
{ |
83
|
53 |
|
$this->style->setFontSize($fontSize); |
84
|
|
|
|
85
|
53 |
|
return $this; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Sets the font color. |
90
|
|
|
* |
91
|
|
|
* @param string $fontColor ARGB color (@see Color) |
92
|
|
|
* @return StyleBuilder |
93
|
|
|
*/ |
94
|
3 |
|
public function setFontColor($fontColor) |
95
|
|
|
{ |
96
|
3 |
|
$this->style->setFontColor($fontColor); |
97
|
|
|
|
98
|
3 |
|
return $this; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Sets the font name. |
103
|
|
|
* |
104
|
|
|
* @param string $fontName Name of the font to use |
105
|
|
|
* @return StyleBuilder |
106
|
|
|
*/ |
107
|
51 |
|
public function setFontName($fontName) |
108
|
|
|
{ |
109
|
51 |
|
$this->style->setFontName($fontName); |
110
|
|
|
|
111
|
51 |
|
return $this; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Makes the text wrap in the cell if requested |
116
|
|
|
* |
117
|
|
|
* @param bool $shouldWrap Should the text be wrapped |
118
|
|
|
* @return StyleBuilder |
119
|
|
|
*/ |
120
|
4 |
|
public function setShouldWrapText($shouldWrap = true) |
121
|
|
|
{ |
122
|
4 |
|
$this->style->setShouldWrapText($shouldWrap); |
123
|
|
|
|
124
|
4 |
|
return $this; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Sets the cell alignment. |
129
|
|
|
* |
130
|
|
|
* @param string $cellAlignment The cell alignment |
131
|
|
|
* |
132
|
|
|
* @throws InvalidArgumentException If the given cell alignment is not valid |
133
|
|
|
* @return StyleBuilder |
134
|
|
|
*/ |
135
|
4 |
|
public function setCellAlignment($cellAlignment) |
136
|
|
|
{ |
137
|
4 |
|
if (!CellAlignment::isValid($cellAlignment)) { |
138
|
1 |
|
throw new InvalidArgumentException('Invalid cell alignment value'); |
139
|
|
|
} |
140
|
|
|
|
141
|
3 |
|
$this->style->setCellAlignment($cellAlignment); |
142
|
|
|
|
143
|
3 |
|
return $this; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* Set a border |
148
|
|
|
* |
149
|
|
|
* @param Border $border |
150
|
|
|
* @return $this |
151
|
|
|
*/ |
152
|
8 |
|
public function setBorder(Border $border) |
153
|
|
|
{ |
154
|
8 |
|
$this->style->setBorder($border); |
155
|
|
|
|
156
|
8 |
|
return $this; |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* Sets a background color |
161
|
|
|
* |
162
|
|
|
* @param string $color ARGB color (@see Color) |
163
|
|
|
* @return StyleBuilder |
164
|
|
|
*/ |
165
|
7 |
|
public function setBackgroundColor($color) |
166
|
|
|
{ |
167
|
7 |
|
$this->style->setBackgroundColor($color); |
168
|
|
|
|
169
|
7 |
|
return $this; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* Sets a format |
174
|
|
|
* |
175
|
|
|
* @param string $format Format |
176
|
|
|
* @return StyleBuilder |
177
|
|
|
* @api |
178
|
|
|
*/ |
179
|
3 |
|
public function setFormat($format) |
180
|
|
|
{ |
181
|
3 |
|
$this->style->setFormat($format); |
182
|
|
|
|
183
|
3 |
|
return $this; |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* Returns the configured style. The style is cached and can be reused. |
188
|
|
|
* |
189
|
|
|
* @return Style |
190
|
|
|
*/ |
191
|
110 |
|
public function build() |
192
|
|
|
{ |
193
|
110 |
|
return $this->style; |
194
|
|
|
} |
195
|
|
|
} |
196
|
|
|
|