1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpOffice\PhpSpreadsheet\Writer\Xls; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Copyright (c) 2006 - 2015 PhpSpreadsheet |
7
|
|
|
* |
8
|
|
|
* This library is free software; you can redistribute it and/or |
9
|
|
|
* modify it under the terms of the GNU Lesser General Public |
10
|
|
|
* License as published by the Free Software Foundation; either |
11
|
|
|
* version 2.1 of the License, or (at your option) any later version. |
12
|
|
|
* |
13
|
|
|
* This library is distributed in the hope that it will be useful, |
14
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
15
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
16
|
|
|
* Lesser General Public License for more details. |
17
|
|
|
* |
18
|
|
|
* You should have received a copy of the GNU Lesser General Public |
19
|
|
|
* License along with this library; if not, write to the Free Software |
20
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
21
|
|
|
* |
22
|
|
|
* @category PhpSpreadsheet |
23
|
|
|
* @copyright Copyright (c) 2006 - 2015 PhpSpreadsheet (https://github.com/PHPOffice/PhpSpreadsheet) |
24
|
|
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
25
|
|
|
*/ |
26
|
|
|
|
27
|
|
|
// Original file header of PEAR::Spreadsheet_Excel_Writer_Format (used as the base for this class): |
28
|
|
|
// ----------------------------------------------------------------------------------------- |
29
|
|
|
// /* |
30
|
|
|
// * Module written/ported by Xavier Noguer <[email protected]> |
31
|
|
|
// * |
32
|
|
|
// * The majority of this is _NOT_ my code. I simply ported it from the |
33
|
|
|
// * PERL Spreadsheet::WriteExcel module. |
34
|
|
|
// * |
35
|
|
|
// * The author of the Spreadsheet::WriteExcel module is John McNamara |
36
|
|
|
// * <[email protected]> |
37
|
|
|
// * |
38
|
|
|
// * I _DO_ maintain this code, and John McNamara has nothing to do with the |
39
|
|
|
// * porting of this code to PHP. Any questions directly related to this |
40
|
|
|
// * class library should be directed to me. |
41
|
|
|
// * |
42
|
|
|
// * License Information: |
43
|
|
|
// * |
44
|
|
|
// * Spreadsheet_Excel_Writer: A library for generating Excel Spreadsheets |
45
|
|
|
// * Copyright (c) 2002-2003 Xavier Noguer [email protected] |
46
|
|
|
// * |
47
|
|
|
// * This library is free software; you can redistribute it and/or |
48
|
|
|
// * modify it under the terms of the GNU Lesser General Public |
49
|
|
|
// * License as published by the Free Software Foundation; either |
50
|
|
|
// * version 2.1 of the License, or (at your option) any later version. |
51
|
|
|
// * |
52
|
|
|
// * This library is distributed in the hope that it will be useful, |
53
|
|
|
// * but WITHOUT ANY WARRANTY; without even the implied warranty of |
54
|
|
|
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
55
|
|
|
// * Lesser General Public License for more details. |
56
|
|
|
// * |
57
|
|
|
// * You should have received a copy of the GNU Lesser General Public |
58
|
|
|
// * License along with this library; if not, write to the Free Software |
59
|
|
|
// * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
60
|
|
|
// */ |
61
|
|
|
class Xf |
62
|
|
|
{ |
63
|
|
|
/** |
64
|
|
|
* Style XF or a cell XF ? |
65
|
|
|
* |
66
|
|
|
* @var bool |
67
|
|
|
*/ |
68
|
|
|
private $isStyleXf; |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Index to the FONT record. Index 4 does not exist |
72
|
|
|
* @var int |
73
|
|
|
*/ |
74
|
|
|
private $fontIndex; |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* An index (2 bytes) to a FORMAT record (number format). |
78
|
|
|
* @var int |
79
|
|
|
*/ |
80
|
|
|
private $numberFormatIndex; |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* 1 bit, apparently not used. |
84
|
|
|
* @var int |
85
|
|
|
*/ |
86
|
|
|
private $textJustLast; |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* The cell's foreground color. |
90
|
|
|
* @var int |
91
|
|
|
*/ |
92
|
|
|
private $foregroundColor; |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* The cell's background color. |
96
|
|
|
* @var int |
97
|
|
|
*/ |
98
|
|
|
private $backgroundColor; |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Color of the bottom border of the cell. |
102
|
|
|
* @var int |
103
|
|
|
*/ |
104
|
|
|
private $bottomBorderColor; |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Color of the top border of the cell. |
108
|
|
|
* @var int |
109
|
|
|
*/ |
110
|
|
|
private $topBorderColor; |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Color of the left border of the cell. |
114
|
|
|
* @var int |
115
|
|
|
*/ |
116
|
|
|
private $leftBorderColor; |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Color of the right border of the cell. |
120
|
|
|
* @var int |
121
|
|
|
*/ |
122
|
|
|
private $rightBorderColor; |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Constructor |
126
|
|
|
* |
127
|
|
|
* @param \PhpOffice\PhpSpreadsheet\Style The XF format |
128
|
|
|
*/ |
129
|
38 |
|
public function __construct(\PhpOffice\PhpSpreadsheet\Style $style = null) |
130
|
|
|
{ |
131
|
38 |
|
$this->isStyleXf = false; |
132
|
38 |
|
$this->fontIndex = 0; |
133
|
|
|
|
134
|
38 |
|
$this->numberFormatIndex = 0; |
135
|
|
|
|
136
|
38 |
|
$this->textJustLast = 0; |
137
|
|
|
|
138
|
38 |
|
$this->foregroundColor = 0x40; |
139
|
38 |
|
$this->backgroundColor = 0x41; |
140
|
|
|
|
141
|
38 |
|
$this->_diag = 0; |
|
|
|
|
142
|
|
|
|
143
|
38 |
|
$this->bottomBorderColor = 0x40; |
144
|
38 |
|
$this->topBorderColor = 0x40; |
145
|
38 |
|
$this->leftBorderColor = 0x40; |
146
|
38 |
|
$this->rightBorderColor = 0x40; |
147
|
38 |
|
$this->_diag_color = 0x40; |
|
|
|
|
148
|
38 |
|
$this->_style = $style; |
|
|
|
|
149
|
38 |
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* Generate an Excel BIFF XF record (style or cell). |
153
|
|
|
* |
154
|
|
|
* @return string The XF record |
155
|
|
|
*/ |
156
|
38 |
|
public function writeXf() |
157
|
|
|
{ |
158
|
|
|
// Set the type of the XF record and some of the attributes. |
159
|
38 |
|
if ($this->isStyleXf) { |
160
|
38 |
|
$style = 0xFFF5; |
161
|
|
|
} else { |
162
|
38 |
|
$style = self::mapLocked($this->_style->getProtection()->getLocked()); |
163
|
38 |
|
$style |= self::mapHidden($this->_style->getProtection()->getHidden()) << 1; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
// Flags to indicate if attributes have been set. |
167
|
38 |
|
$atr_num = ($this->numberFormatIndex != 0) ? 1 : 0; |
168
|
38 |
|
$atr_fnt = ($this->fontIndex != 0) ? 1 : 0; |
169
|
38 |
|
$atr_alc = ((int) $this->_style->getAlignment()->getWrapText()) ? 1 : 0; |
170
|
38 |
|
$atr_bdr = (self::mapBorderStyle($this->_style->getBorders()->getBottom()->getBorderStyle()) || |
171
|
38 |
|
self::mapBorderStyle($this->_style->getBorders()->getTop()->getBorderStyle()) || |
172
|
38 |
|
self::mapBorderStyle($this->_style->getBorders()->getLeft()->getBorderStyle()) || |
173
|
38 |
|
self::mapBorderStyle($this->_style->getBorders()->getRight()->getBorderStyle())) ? 1 : 0; |
174
|
38 |
|
$atr_pat = (($this->foregroundColor != 0x40) || |
175
|
|
|
($this->backgroundColor != 0x41) || |
176
|
38 |
|
self::mapFillType($this->_style->getFill()->getFillType())) ? 1 : 0; |
177
|
38 |
|
$atr_prot = self::mapLocked($this->_style->getProtection()->getLocked()) |
178
|
38 |
|
| self::mapHidden($this->_style->getProtection()->getHidden()); |
179
|
|
|
|
180
|
|
|
// Zero the default border colour if the border has not been set. |
181
|
38 |
|
if (self::mapBorderStyle($this->_style->getBorders()->getBottom()->getBorderStyle()) == 0) { |
182
|
38 |
|
$this->bottomBorderColor = 0; |
183
|
|
|
} |
184
|
38 |
|
if (self::mapBorderStyle($this->_style->getBorders()->getTop()->getBorderStyle()) == 0) { |
185
|
38 |
|
$this->topBorderColor = 0; |
186
|
|
|
} |
187
|
38 |
|
if (self::mapBorderStyle($this->_style->getBorders()->getRight()->getBorderStyle()) == 0) { |
188
|
38 |
|
$this->rightBorderColor = 0; |
189
|
|
|
} |
190
|
38 |
|
if (self::mapBorderStyle($this->_style->getBorders()->getLeft()->getBorderStyle()) == 0) { |
191
|
38 |
|
$this->leftBorderColor = 0; |
192
|
|
|
} |
193
|
38 |
|
if (self::mapBorderStyle($this->_style->getBorders()->getDiagonal()->getBorderStyle()) == 0) { |
194
|
38 |
|
$this->_diag_color = 0; |
195
|
|
|
} |
196
|
|
|
|
197
|
38 |
|
$record = 0x00E0; // Record identifier |
198
|
38 |
|
$length = 0x0014; // Number of bytes to follow |
199
|
|
|
|
200
|
38 |
|
$ifnt = $this->fontIndex; // Index to FONT record |
201
|
38 |
|
$ifmt = $this->numberFormatIndex; // Index to FORMAT record |
202
|
|
|
|
203
|
38 |
|
$align = $this->mapHAlign($this->_style->getAlignment()->getHorizontal()); // Alignment |
204
|
38 |
|
$align |= (int) $this->_style->getAlignment()->getWrapText() << 3; |
205
|
38 |
|
$align |= self::mapVAlign($this->_style->getAlignment()->getVertical()) << 4; |
206
|
38 |
|
$align |= $this->textJustLast << 7; |
207
|
|
|
|
208
|
38 |
|
$used_attrib = $atr_num << 2; |
209
|
38 |
|
$used_attrib |= $atr_fnt << 3; |
210
|
38 |
|
$used_attrib |= $atr_alc << 4; |
211
|
38 |
|
$used_attrib |= $atr_bdr << 5; |
212
|
38 |
|
$used_attrib |= $atr_pat << 6; |
213
|
38 |
|
$used_attrib |= $atr_prot << 7; |
214
|
|
|
|
215
|
38 |
|
$icv = $this->foregroundColor; // fg and bg pattern colors |
216
|
38 |
|
$icv |= $this->backgroundColor << 7; |
217
|
|
|
|
218
|
38 |
|
$border1 = self::mapBorderStyle($this->_style->getBorders()->getLeft()->getBorderStyle()); // Border line style and color |
219
|
38 |
|
$border1 |= self::mapBorderStyle($this->_style->getBorders()->getRight()->getBorderStyle()) << 4; |
220
|
38 |
|
$border1 |= self::mapBorderStyle($this->_style->getBorders()->getTop()->getBorderStyle()) << 8; |
221
|
38 |
|
$border1 |= self::mapBorderStyle($this->_style->getBorders()->getBottom()->getBorderStyle()) << 12; |
222
|
38 |
|
$border1 |= $this->leftBorderColor << 16; |
223
|
38 |
|
$border1 |= $this->rightBorderColor << 23; |
224
|
|
|
|
225
|
38 |
|
$diagonalDirection = $this->_style->getBorders()->getDiagonalDirection(); |
226
|
38 |
|
$diag_tl_to_rb = $diagonalDirection == \PhpOffice\PhpSpreadsheet\Style\Borders::DIAGONAL_BOTH |
227
|
38 |
|
|| $diagonalDirection == \PhpOffice\PhpSpreadsheet\Style\Borders::DIAGONAL_DOWN; |
228
|
38 |
|
$diag_tr_to_lb = $diagonalDirection == \PhpOffice\PhpSpreadsheet\Style\Borders::DIAGONAL_BOTH |
229
|
38 |
|
|| $diagonalDirection == \PhpOffice\PhpSpreadsheet\Style\Borders::DIAGONAL_UP; |
230
|
38 |
|
$border1 |= $diag_tl_to_rb << 30; |
231
|
38 |
|
$border1 |= $diag_tr_to_lb << 31; |
232
|
|
|
|
233
|
38 |
|
$border2 = $this->topBorderColor; // Border color |
234
|
38 |
|
$border2 |= $this->bottomBorderColor << 7; |
235
|
38 |
|
$border2 |= $this->_diag_color << 14; |
236
|
38 |
|
$border2 |= self::mapBorderStyle($this->_style->getBorders()->getDiagonal()->getBorderStyle()) << 21; |
237
|
38 |
|
$border2 |= self::mapFillType($this->_style->getFill()->getFillType()) << 26; |
238
|
|
|
|
239
|
38 |
|
$header = pack('vv', $record, $length); |
240
|
|
|
|
241
|
|
|
//BIFF8 options: identation, shrinkToFit and text direction |
242
|
38 |
|
$biff8_options = $this->_style->getAlignment()->getIndent(); |
243
|
38 |
|
$biff8_options |= (int) $this->_style->getAlignment()->getShrinkToFit() << 4; |
244
|
|
|
|
245
|
38 |
|
$data = pack('vvvC', $ifnt, $ifmt, $style, $align); |
246
|
38 |
|
$data .= pack('CCC', self::mapTextRotation($this->_style->getAlignment()->getTextRotation()), $biff8_options, $used_attrib); |
247
|
38 |
|
$data .= pack('VVv', $border1, $border2, $icv); |
248
|
|
|
|
249
|
38 |
|
return $header . $data; |
250
|
|
|
} |
251
|
|
|
|
252
|
|
|
/** |
253
|
|
|
* Is this a style XF ? |
254
|
|
|
* |
255
|
|
|
* @param bool $value |
256
|
|
|
*/ |
257
|
38 |
|
public function setIsStyleXf($value) |
258
|
|
|
{ |
259
|
38 |
|
$this->isStyleXf = $value; |
260
|
38 |
|
} |
261
|
|
|
|
262
|
|
|
/** |
263
|
|
|
* Sets the cell's bottom border color |
264
|
|
|
* |
265
|
|
|
* @param int $colorIndex Color index |
266
|
|
|
*/ |
267
|
38 |
|
public function setBottomColor($colorIndex) |
268
|
|
|
{ |
269
|
38 |
|
$this->bottomBorderColor = $colorIndex; |
270
|
38 |
|
} |
271
|
|
|
|
272
|
|
|
/** |
273
|
|
|
* Sets the cell's top border color |
274
|
|
|
* |
275
|
|
|
* @param int $colorIndex Color index |
276
|
|
|
*/ |
277
|
38 |
|
public function setTopColor($colorIndex) |
278
|
|
|
{ |
279
|
38 |
|
$this->topBorderColor = $colorIndex; |
280
|
38 |
|
} |
281
|
|
|
|
282
|
|
|
/** |
283
|
|
|
* Sets the cell's left border color |
284
|
|
|
* |
285
|
|
|
* @param int $colorIndex Color index |
286
|
|
|
*/ |
287
|
38 |
|
public function setLeftColor($colorIndex) |
288
|
|
|
{ |
289
|
38 |
|
$this->leftBorderColor = $colorIndex; |
290
|
38 |
|
} |
291
|
|
|
|
292
|
|
|
/** |
293
|
|
|
* Sets the cell's right border color |
294
|
|
|
* |
295
|
|
|
* @param int $colorIndex Color index |
296
|
|
|
*/ |
297
|
38 |
|
public function setRightColor($colorIndex) |
298
|
|
|
{ |
299
|
38 |
|
$this->rightBorderColor = $colorIndex; |
300
|
38 |
|
} |
301
|
|
|
|
302
|
|
|
/** |
303
|
|
|
* Sets the cell's diagonal border color |
304
|
|
|
* |
305
|
|
|
* @param int $colorIndex Color index |
306
|
|
|
*/ |
307
|
38 |
|
public function setDiagColor($colorIndex) |
308
|
|
|
{ |
309
|
38 |
|
$this->_diag_color = $colorIndex; |
310
|
38 |
|
} |
311
|
|
|
|
312
|
|
|
/** |
313
|
|
|
* Sets the cell's foreground color |
314
|
|
|
* |
315
|
|
|
* @param int $colorIndex Color index |
316
|
|
|
*/ |
317
|
38 |
|
public function setFgColor($colorIndex) |
318
|
|
|
{ |
319
|
38 |
|
$this->foregroundColor = $colorIndex; |
320
|
38 |
|
} |
321
|
|
|
|
322
|
|
|
/** |
323
|
|
|
* Sets the cell's background color |
324
|
|
|
* |
325
|
|
|
* @param int $colorIndex Color index |
326
|
|
|
*/ |
327
|
38 |
|
public function setBgColor($colorIndex) |
328
|
|
|
{ |
329
|
38 |
|
$this->backgroundColor = $colorIndex; |
330
|
38 |
|
} |
331
|
|
|
|
332
|
|
|
/** |
333
|
|
|
* Sets the index to the number format record |
334
|
|
|
* It can be date, time, currency, etc... |
335
|
|
|
* |
336
|
|
|
* @param int $numberFormatIndex Index to format record |
337
|
|
|
*/ |
338
|
38 |
|
public function setNumberFormatIndex($numberFormatIndex) |
339
|
|
|
{ |
340
|
38 |
|
$this->numberFormatIndex = $numberFormatIndex; |
341
|
38 |
|
} |
342
|
|
|
|
343
|
|
|
/** |
344
|
|
|
* Set the font index. |
345
|
|
|
* |
346
|
|
|
* @param int $value Font index, note that value 4 does not exist |
347
|
|
|
*/ |
348
|
38 |
|
public function setFontIndex($value) |
349
|
|
|
{ |
350
|
38 |
|
$this->fontIndex = $value; |
351
|
38 |
|
} |
352
|
|
|
|
353
|
|
|
/** |
354
|
|
|
* Map of BIFF2-BIFF8 codes for border styles |
355
|
|
|
* @static array of int |
356
|
|
|
*/ |
357
|
|
|
private static $mapBorderStyles = [ |
358
|
|
|
\PhpOffice\PhpSpreadsheet\Style\Border::BORDER_NONE => 0x00, |
359
|
|
|
\PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN => 0x01, |
360
|
|
|
\PhpOffice\PhpSpreadsheet\Style\Border::BORDER_MEDIUM => 0x02, |
361
|
|
|
\PhpOffice\PhpSpreadsheet\Style\Border::BORDER_DASHED => 0x03, |
362
|
|
|
\PhpOffice\PhpSpreadsheet\Style\Border::BORDER_DOTTED => 0x04, |
363
|
|
|
\PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THICK => 0x05, |
364
|
|
|
\PhpOffice\PhpSpreadsheet\Style\Border::BORDER_DOUBLE => 0x06, |
365
|
|
|
\PhpOffice\PhpSpreadsheet\Style\Border::BORDER_HAIR => 0x07, |
366
|
|
|
\PhpOffice\PhpSpreadsheet\Style\Border::BORDER_MEDIUMDASHED => 0x08, |
367
|
|
|
\PhpOffice\PhpSpreadsheet\Style\Border::BORDER_DASHDOT => 0x09, |
368
|
|
|
\PhpOffice\PhpSpreadsheet\Style\Border::BORDER_MEDIUMDASHDOT => 0x0A, |
369
|
|
|
\PhpOffice\PhpSpreadsheet\Style\Border::BORDER_DASHDOTDOT => 0x0B, |
370
|
|
|
\PhpOffice\PhpSpreadsheet\Style\Border::BORDER_MEDIUMDASHDOTDOT => 0x0C, |
371
|
|
|
\PhpOffice\PhpSpreadsheet\Style\Border::BORDER_SLANTDASHDOT => 0x0D, |
372
|
|
|
]; |
373
|
|
|
|
374
|
|
|
/** |
375
|
|
|
* Map border style |
376
|
|
|
* |
377
|
|
|
* @param string $borderStyle |
378
|
|
|
* @return int |
379
|
|
|
*/ |
380
|
38 |
|
private static function mapBorderStyle($borderStyle) |
381
|
|
|
{ |
382
|
38 |
|
if (isset(self::$mapBorderStyles[$borderStyle])) { |
383
|
38 |
|
return self::$mapBorderStyles[$borderStyle]; |
384
|
|
|
} |
385
|
|
|
|
386
|
|
|
return 0x00; |
387
|
|
|
} |
388
|
|
|
|
389
|
|
|
/** |
390
|
|
|
* Map of BIFF2-BIFF8 codes for fill types |
391
|
|
|
* @static array of int |
392
|
|
|
*/ |
393
|
|
|
private static $mapFillTypes = [ |
394
|
|
|
\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_NONE => 0x00, |
395
|
|
|
\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID => 0x01, |
396
|
|
|
\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_MEDIUMGRAY => 0x02, |
397
|
|
|
\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_DARKGRAY => 0x03, |
398
|
|
|
\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_LIGHTGRAY => 0x04, |
399
|
|
|
\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_DARKHORIZONTAL => 0x05, |
400
|
|
|
\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_DARKVERTICAL => 0x06, |
401
|
|
|
\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_DARKDOWN => 0x07, |
402
|
|
|
\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_DARKUP => 0x08, |
403
|
|
|
\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_DARKGRID => 0x09, |
404
|
|
|
\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_DARKTRELLIS => 0x0A, |
405
|
|
|
\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_LIGHTHORIZONTAL => 0x0B, |
406
|
|
|
\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_LIGHTVERTICAL => 0x0C, |
407
|
|
|
\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_LIGHTDOWN => 0x0D, |
408
|
|
|
\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_LIGHTUP => 0x0E, |
409
|
|
|
\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_LIGHTGRID => 0x0F, |
410
|
|
|
\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_LIGHTTRELLIS => 0x10, |
411
|
|
|
\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_GRAY125 => 0x11, |
412
|
|
|
\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_GRAY0625 => 0x12, |
413
|
|
|
\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_GRADIENT_LINEAR => 0x00, // does not exist in BIFF8 |
414
|
|
|
\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_GRADIENT_PATH => 0x00, // does not exist in BIFF8 |
415
|
|
|
]; |
416
|
|
|
|
417
|
|
|
/** |
418
|
|
|
* Map fill type |
419
|
|
|
* |
420
|
|
|
* @param string $fillType |
421
|
|
|
* @return int |
422
|
|
|
*/ |
423
|
38 |
|
private static function mapFillType($fillType) |
424
|
|
|
{ |
425
|
38 |
|
if (isset(self::$mapFillTypes[$fillType])) { |
426
|
38 |
|
return self::$mapFillTypes[$fillType]; |
427
|
|
|
} |
428
|
|
|
|
429
|
|
|
return 0x00; |
430
|
|
|
} |
431
|
|
|
|
432
|
|
|
/** |
433
|
|
|
* Map of BIFF2-BIFF8 codes for horizontal alignment |
434
|
|
|
* @static array of int |
435
|
|
|
*/ |
436
|
|
|
private static $mapHAlignments = [ |
437
|
|
|
\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_GENERAL => 0, |
438
|
|
|
\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_LEFT => 1, |
439
|
|
|
\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER => 2, |
440
|
|
|
\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_RIGHT => 3, |
441
|
|
|
\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_FILL => 4, |
442
|
|
|
\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_JUSTIFY => 5, |
443
|
|
|
\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER_CONTINUOUS => 6, |
444
|
|
|
]; |
445
|
|
|
|
446
|
|
|
/** |
447
|
|
|
* Map to BIFF2-BIFF8 codes for horizontal alignment |
448
|
|
|
* |
449
|
|
|
* @param string $hAlign |
450
|
|
|
* @return int |
451
|
|
|
*/ |
452
|
38 |
|
private function mapHAlign($hAlign) |
453
|
|
|
{ |
454
|
38 |
|
if (isset(self::$mapHAlignments[$hAlign])) { |
455
|
38 |
|
return self::$mapHAlignments[$hAlign]; |
456
|
|
|
} |
457
|
|
|
|
458
|
|
|
return 0; |
459
|
|
|
} |
460
|
|
|
|
461
|
|
|
/** |
462
|
|
|
* Map of BIFF2-BIFF8 codes for vertical alignment |
463
|
|
|
* @static array of int |
464
|
|
|
*/ |
465
|
|
|
private static $mapVAlignments = [ |
466
|
|
|
\PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_TOP => 0, |
467
|
|
|
\PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER => 1, |
468
|
|
|
\PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_BOTTOM => 2, |
469
|
|
|
\PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_JUSTIFY => 3, |
470
|
|
|
]; |
471
|
|
|
|
472
|
|
|
/** |
473
|
|
|
* Map to BIFF2-BIFF8 codes for vertical alignment |
474
|
|
|
* |
475
|
|
|
* @param string $vAlign |
476
|
|
|
* @return int |
477
|
|
|
*/ |
478
|
38 |
|
private static function mapVAlign($vAlign) |
479
|
|
|
{ |
480
|
38 |
|
if (isset(self::$mapVAlignments[$vAlign])) { |
481
|
38 |
|
return self::$mapVAlignments[$vAlign]; |
482
|
|
|
} |
483
|
|
|
|
484
|
|
|
return 2; |
485
|
|
|
} |
486
|
|
|
|
487
|
|
|
/** |
488
|
|
|
* Map to BIFF8 codes for text rotation angle |
489
|
|
|
* |
490
|
|
|
* @param int $textRotation |
491
|
|
|
* @return int |
492
|
|
|
*/ |
493
|
38 |
|
private static function mapTextRotation($textRotation) |
494
|
|
|
{ |
495
|
38 |
|
if ($textRotation >= 0) { |
496
|
38 |
|
return $textRotation; |
497
|
|
|
} elseif ($textRotation == -165) { |
498
|
|
|
return 255; |
499
|
|
|
} elseif ($textRotation < 0) { |
500
|
|
|
return 90 - $textRotation; |
501
|
|
|
} |
502
|
|
|
} |
503
|
|
|
|
504
|
|
|
/** |
505
|
|
|
* Map locked |
506
|
|
|
* |
507
|
|
|
* @param string |
508
|
|
|
* @return int |
509
|
|
|
*/ |
510
|
38 |
|
private static function mapLocked($locked) |
511
|
|
|
{ |
512
|
|
|
switch ($locked) { |
513
|
38 |
|
case \PhpOffice\PhpSpreadsheet\Style\Protection::PROTECTION_INHERIT: |
514
|
38 |
|
return 1; |
515
|
7 |
|
case \PhpOffice\PhpSpreadsheet\Style\Protection::PROTECTION_PROTECTED: |
516
|
|
|
return 1; |
517
|
7 |
|
case \PhpOffice\PhpSpreadsheet\Style\Protection::PROTECTION_UNPROTECTED: |
518
|
7 |
|
return 0; |
519
|
|
|
default: |
520
|
|
|
return 1; |
521
|
|
|
} |
522
|
|
|
} |
523
|
|
|
|
524
|
|
|
/** |
525
|
|
|
* Map hidden |
526
|
|
|
* |
527
|
|
|
* @param string |
528
|
|
|
* @return int |
529
|
|
|
*/ |
530
|
38 |
|
private static function mapHidden($hidden) |
531
|
|
|
{ |
532
|
|
|
switch ($hidden) { |
533
|
38 |
|
case \PhpOffice\PhpSpreadsheet\Style\Protection::PROTECTION_INHERIT: |
534
|
35 |
|
return 0; |
535
|
4 |
|
case \PhpOffice\PhpSpreadsheet\Style\Protection::PROTECTION_PROTECTED: |
536
|
|
|
return 1; |
537
|
4 |
|
case \PhpOffice\PhpSpreadsheet\Style\Protection::PROTECTION_UNPROTECTED: |
538
|
4 |
|
return 0; |
539
|
|
|
default: |
540
|
|
|
return 0; |
541
|
|
|
} |
542
|
|
|
} |
543
|
|
|
} |
544
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: