1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpOffice\PhpSpreadsheet\Worksheet; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* <code> |
7
|
|
|
* Header/Footer Formatting Syntax taken from Office Open XML Part 4 - Markup Language Reference, page 1970:. |
8
|
|
|
* |
9
|
|
|
* There are a number of formatting codes that can be written inline with the actual header / footer text, which |
10
|
|
|
* affect the formatting in the header or footer. |
11
|
|
|
* |
12
|
|
|
* Example: This example shows the text "Center Bold Header" on the first line (center section), and the date on |
13
|
|
|
* the second line (center section). |
14
|
|
|
* &CCenter &"-,Bold"Bold&"-,Regular"Header_x000A_&D |
15
|
|
|
* |
16
|
|
|
* General Rules: |
17
|
|
|
* There is no required order in which these codes must appear. |
18
|
|
|
* |
19
|
|
|
* The first occurrence of the following codes turns the formatting ON, the second occurrence turns it OFF again: |
20
|
|
|
* - strikethrough |
21
|
|
|
* - superscript |
22
|
|
|
* - subscript |
23
|
|
|
* Superscript and subscript cannot both be ON at same time. Whichever comes first wins and the other is ignored, |
24
|
|
|
* while the first is ON. |
25
|
|
|
* &L - code for "left section" (there are three header / footer locations, "left", "center", and "right"). When |
26
|
|
|
* two or more occurrences of this section marker exist, the contents from all markers are concatenated, in the |
27
|
|
|
* order of appearance, and placed into the left section. |
28
|
|
|
* &P - code for "current page #" |
29
|
|
|
* &N - code for "total pages" |
30
|
|
|
* &font size - code for "text font size", where font size is a font size in points. |
31
|
|
|
* &K - code for "text font color" |
32
|
|
|
* RGB Color is specified as RRGGBB |
33
|
|
|
* Theme Color is specifed as TTSNN where TT is the theme color Id, S is either "+" or "-" of the tint/shade |
34
|
|
|
* value, NN is the tint/shade value. |
35
|
|
|
* &S - code for "text strikethrough" on / off |
36
|
|
|
* &X - code for "text super script" on / off |
37
|
|
|
* &Y - code for "text subscript" on / off |
38
|
|
|
* &C - code for "center section". When two or more occurrences of this section marker exist, the contents |
39
|
|
|
* from all markers are concatenated, in the order of appearance, and placed into the center section. |
40
|
|
|
* |
41
|
|
|
* &D - code for "date" |
42
|
|
|
* &T - code for "time" |
43
|
|
|
* &G - code for "picture as background" |
44
|
|
|
* &U - code for "text single underline" |
45
|
|
|
* &E - code for "double underline" |
46
|
|
|
* &R - code for "right section". When two or more occurrences of this section marker exist, the contents |
47
|
|
|
* from all markers are concatenated, in the order of appearance, and placed into the right section. |
48
|
|
|
* &Z - code for "this workbook's file path" |
49
|
|
|
* &F - code for "this workbook's file name" |
50
|
|
|
* &A - code for "sheet tab name" |
51
|
|
|
* &+ - code for add to page #. |
52
|
|
|
* &- - code for subtract from page #. |
53
|
|
|
* &"font name,font type" - code for "text font name" and "text font type", where font name and font type |
54
|
|
|
* are strings specifying the name and type of the font, separated by a comma. When a hyphen appears in font |
55
|
|
|
* name, it means "none specified". Both of font name and font type can be localized values. |
56
|
|
|
* &"-,Bold" - code for "bold font style" |
57
|
|
|
* &B - also means "bold font style". |
58
|
|
|
* &"-,Regular" - code for "regular font style" |
59
|
|
|
* &"-,Italic" - code for "italic font style" |
60
|
|
|
* &I - also means "italic font style" |
61
|
|
|
* &"-,Bold Italic" code for "bold italic font style" |
62
|
|
|
* &O - code for "outline style" |
63
|
|
|
* &H - code for "shadow style" |
64
|
|
|
* </code> |
65
|
|
|
*/ |
66
|
|
|
class HeaderFooter |
67
|
|
|
{ |
68
|
|
|
// Header/footer image location |
69
|
|
|
const IMAGE_HEADER_LEFT = 'LH'; |
70
|
|
|
const IMAGE_HEADER_CENTER = 'CH'; |
71
|
|
|
const IMAGE_HEADER_RIGHT = 'RH'; |
72
|
|
|
const IMAGE_FOOTER_LEFT = 'LF'; |
73
|
|
|
const IMAGE_FOOTER_CENTER = 'CF'; |
74
|
|
|
const IMAGE_FOOTER_RIGHT = 'RF'; |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* OddHeader. |
78
|
|
|
* |
79
|
|
|
* @var string |
80
|
|
|
*/ |
81
|
|
|
private $oddHeader = ''; |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* OddFooter. |
85
|
|
|
* |
86
|
|
|
* @var string |
87
|
|
|
*/ |
88
|
|
|
private $oddFooter = ''; |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* EvenHeader. |
92
|
|
|
* |
93
|
|
|
* @var string |
94
|
|
|
*/ |
95
|
|
|
private $evenHeader = ''; |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* EvenFooter. |
99
|
|
|
* |
100
|
|
|
* @var string |
101
|
|
|
*/ |
102
|
|
|
private $evenFooter = ''; |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* FirstHeader. |
106
|
|
|
* |
107
|
|
|
* @var string |
108
|
|
|
*/ |
109
|
|
|
private $firstHeader = ''; |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* FirstFooter. |
113
|
|
|
* |
114
|
|
|
* @var string |
115
|
|
|
*/ |
116
|
|
|
private $firstFooter = ''; |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Different header for Odd/Even, defaults to false. |
120
|
|
|
* |
121
|
|
|
* @var bool |
122
|
|
|
*/ |
123
|
|
|
private $differentOddEven = false; |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* Different header for first page, defaults to false. |
127
|
|
|
* |
128
|
|
|
* @var bool |
129
|
|
|
*/ |
130
|
|
|
private $differentFirst = false; |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* Scale with document, defaults to true. |
134
|
|
|
* |
135
|
|
|
* @var bool |
136
|
|
|
*/ |
137
|
|
|
private $scaleWithDocument = true; |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* Align with margins, defaults to true. |
141
|
|
|
* |
142
|
|
|
* @var bool |
143
|
|
|
*/ |
144
|
|
|
private $alignWithMargins = true; |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* Header/footer images. |
148
|
|
|
* |
149
|
|
|
* @var HeaderFooterDrawing[] |
150
|
|
|
*/ |
151
|
|
|
private $headerFooterImages = []; |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* Create a new HeaderFooter. |
155
|
|
|
*/ |
156
|
174 |
|
public function __construct() |
157
|
|
|
{ |
158
|
174 |
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* Get OddHeader. |
162
|
|
|
* |
163
|
|
|
* @return string |
164
|
|
|
*/ |
165
|
65 |
|
public function getOddHeader() |
166
|
|
|
{ |
167
|
65 |
|
return $this->oddHeader; |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* Set OddHeader. |
172
|
|
|
* |
173
|
|
|
* @param string $pValue |
174
|
|
|
* |
175
|
|
|
* @return HeaderFooter |
176
|
|
|
*/ |
177
|
29 |
|
public function setOddHeader($pValue) |
178
|
|
|
{ |
179
|
29 |
|
$this->oddHeader = $pValue; |
180
|
|
|
|
181
|
29 |
|
return $this; |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* Get OddFooter. |
186
|
|
|
* |
187
|
|
|
* @return string |
188
|
|
|
*/ |
189
|
65 |
|
public function getOddFooter() |
190
|
|
|
{ |
191
|
65 |
|
return $this->oddFooter; |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* Set OddFooter. |
196
|
|
|
* |
197
|
|
|
* @param string $pValue |
198
|
|
|
* |
199
|
|
|
* @return HeaderFooter |
200
|
|
|
*/ |
201
|
29 |
|
public function setOddFooter($pValue) |
202
|
|
|
{ |
203
|
29 |
|
$this->oddFooter = $pValue; |
204
|
|
|
|
205
|
29 |
|
return $this; |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
/** |
209
|
|
|
* Get EvenHeader. |
210
|
|
|
* |
211
|
|
|
* @return string |
212
|
|
|
*/ |
213
|
60 |
|
public function getEvenHeader() |
214
|
|
|
{ |
215
|
60 |
|
return $this->evenHeader; |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
/** |
219
|
|
|
* Set EvenHeader. |
220
|
|
|
* |
221
|
|
|
* @param string $pValue |
222
|
|
|
* |
223
|
|
|
* @return HeaderFooter |
224
|
|
|
*/ |
225
|
18 |
|
public function setEvenHeader($pValue) |
226
|
|
|
{ |
227
|
18 |
|
$this->evenHeader = $pValue; |
228
|
|
|
|
229
|
18 |
|
return $this; |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
/** |
233
|
|
|
* Get EvenFooter. |
234
|
|
|
* |
235
|
|
|
* @return string |
236
|
|
|
*/ |
237
|
60 |
|
public function getEvenFooter() |
238
|
|
|
{ |
239
|
60 |
|
return $this->evenFooter; |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
/** |
243
|
|
|
* Set EvenFooter. |
244
|
|
|
* |
245
|
|
|
* @param string $pValue |
246
|
|
|
* |
247
|
|
|
* @return HeaderFooter |
248
|
|
|
*/ |
249
|
18 |
|
public function setEvenFooter($pValue) |
250
|
|
|
{ |
251
|
18 |
|
$this->evenFooter = $pValue; |
252
|
|
|
|
253
|
18 |
|
return $this; |
254
|
|
|
} |
255
|
|
|
|
256
|
|
|
/** |
257
|
|
|
* Get FirstHeader. |
258
|
|
|
* |
259
|
|
|
* @return string |
260
|
|
|
*/ |
261
|
60 |
|
public function getFirstHeader() |
262
|
|
|
{ |
263
|
60 |
|
return $this->firstHeader; |
264
|
|
|
} |
265
|
|
|
|
266
|
|
|
/** |
267
|
|
|
* Set FirstHeader. |
268
|
|
|
* |
269
|
|
|
* @param string $pValue |
270
|
|
|
* |
271
|
|
|
* @return HeaderFooter |
272
|
|
|
*/ |
273
|
11 |
|
public function setFirstHeader($pValue) |
274
|
|
|
{ |
275
|
11 |
|
$this->firstHeader = $pValue; |
276
|
|
|
|
277
|
11 |
|
return $this; |
278
|
|
|
} |
279
|
|
|
|
280
|
|
|
/** |
281
|
|
|
* Get FirstFooter. |
282
|
|
|
* |
283
|
|
|
* @return string |
284
|
|
|
*/ |
285
|
60 |
|
public function getFirstFooter() |
286
|
|
|
{ |
287
|
60 |
|
return $this->firstFooter; |
288
|
|
|
} |
289
|
|
|
|
290
|
|
|
/** |
291
|
|
|
* Set FirstFooter. |
292
|
|
|
* |
293
|
|
|
* @param string $pValue |
294
|
|
|
* |
295
|
|
|
* @return HeaderFooter |
296
|
|
|
*/ |
297
|
11 |
|
public function setFirstFooter($pValue) |
298
|
|
|
{ |
299
|
11 |
|
$this->firstFooter = $pValue; |
300
|
|
|
|
301
|
11 |
|
return $this; |
302
|
|
|
} |
303
|
|
|
|
304
|
|
|
/** |
305
|
|
|
* Get DifferentOddEven. |
306
|
|
|
* |
307
|
|
|
* @return bool |
308
|
|
|
*/ |
309
|
60 |
|
public function getDifferentOddEven() |
310
|
|
|
{ |
311
|
60 |
|
return $this->differentOddEven; |
312
|
|
|
} |
313
|
|
|
|
314
|
|
|
/** |
315
|
|
|
* Set DifferentOddEven. |
316
|
|
|
* |
317
|
|
|
* @param bool $pValue |
318
|
|
|
* |
319
|
|
|
* @return HeaderFooter |
320
|
|
|
*/ |
321
|
11 |
|
public function setDifferentOddEven($pValue) |
322
|
|
|
{ |
323
|
11 |
|
$this->differentOddEven = $pValue; |
324
|
|
|
|
325
|
11 |
|
return $this; |
326
|
|
|
} |
327
|
|
|
|
328
|
|
|
/** |
329
|
|
|
* Get DifferentFirst. |
330
|
|
|
* |
331
|
|
|
* @return bool |
332
|
|
|
*/ |
333
|
60 |
|
public function getDifferentFirst() |
334
|
|
|
{ |
335
|
60 |
|
return $this->differentFirst; |
336
|
|
|
} |
337
|
|
|
|
338
|
|
|
/** |
339
|
|
|
* Set DifferentFirst. |
340
|
|
|
* |
341
|
|
|
* @param bool $pValue |
342
|
|
|
* |
343
|
|
|
* @return HeaderFooter |
344
|
|
|
*/ |
345
|
11 |
|
public function setDifferentFirst($pValue) |
346
|
|
|
{ |
347
|
11 |
|
$this->differentFirst = $pValue; |
348
|
|
|
|
349
|
11 |
|
return $this; |
350
|
|
|
} |
351
|
|
|
|
352
|
|
|
/** |
353
|
|
|
* Get ScaleWithDocument. |
354
|
|
|
* |
355
|
|
|
* @return bool |
356
|
|
|
*/ |
357
|
60 |
|
public function getScaleWithDocument() |
358
|
|
|
{ |
359
|
60 |
|
return $this->scaleWithDocument; |
360
|
|
|
} |
361
|
|
|
|
362
|
|
|
/** |
363
|
|
|
* Set ScaleWithDocument. |
364
|
|
|
* |
365
|
|
|
* @param bool $pValue |
366
|
|
|
* |
367
|
|
|
* @return HeaderFooter |
368
|
|
|
*/ |
369
|
11 |
|
public function setScaleWithDocument($pValue) |
370
|
|
|
{ |
371
|
11 |
|
$this->scaleWithDocument = $pValue; |
372
|
|
|
|
373
|
11 |
|
return $this; |
374
|
|
|
} |
375
|
|
|
|
376
|
|
|
/** |
377
|
|
|
* Get AlignWithMargins. |
378
|
|
|
* |
379
|
|
|
* @return bool |
380
|
|
|
*/ |
381
|
60 |
|
public function getAlignWithMargins() |
382
|
|
|
{ |
383
|
60 |
|
return $this->alignWithMargins; |
384
|
|
|
} |
385
|
|
|
|
386
|
|
|
/** |
387
|
|
|
* Set AlignWithMargins. |
388
|
|
|
* |
389
|
|
|
* @param bool $pValue |
390
|
|
|
* |
391
|
|
|
* @return HeaderFooter |
392
|
|
|
*/ |
393
|
11 |
|
public function setAlignWithMargins($pValue) |
394
|
|
|
{ |
395
|
11 |
|
$this->alignWithMargins = $pValue; |
396
|
|
|
|
397
|
11 |
|
return $this; |
398
|
|
|
} |
399
|
|
|
|
400
|
|
|
/** |
401
|
|
|
* Add header/footer image. |
402
|
|
|
* |
403
|
|
|
* @param HeaderFooterDrawing $image |
404
|
|
|
* @param string $location |
405
|
|
|
* |
406
|
|
|
* @return HeaderFooter |
407
|
|
|
*/ |
408
|
1 |
|
public function addImage(HeaderFooterDrawing $image, $location = self::IMAGE_HEADER_LEFT) |
409
|
|
|
{ |
410
|
1 |
|
$this->headerFooterImages[$location] = $image; |
411
|
|
|
|
412
|
1 |
|
return $this; |
413
|
|
|
} |
414
|
|
|
|
415
|
|
|
/** |
416
|
|
|
* Remove header/footer image. |
417
|
|
|
* |
418
|
|
|
* @param string $location |
419
|
|
|
* |
420
|
|
|
* @return HeaderFooter |
421
|
|
|
*/ |
422
|
|
|
public function removeImage($location = self::IMAGE_HEADER_LEFT) |
423
|
|
|
{ |
424
|
|
|
if (isset($this->headerFooterImages[$location])) { |
425
|
|
|
unset($this->headerFooterImages[$location]); |
426
|
|
|
} |
427
|
|
|
|
428
|
|
|
return $this; |
429
|
|
|
} |
430
|
|
|
|
431
|
|
|
/** |
432
|
|
|
* Set header/footer images. |
433
|
|
|
* |
434
|
|
|
* @param HeaderFooterDrawing[] $images |
435
|
|
|
* |
436
|
|
|
* @return HeaderFooter |
437
|
|
|
*/ |
438
|
|
|
public function setImages(array $images) |
439
|
|
|
{ |
440
|
|
|
$this->headerFooterImages = $images; |
441
|
|
|
|
442
|
|
|
return $this; |
443
|
|
|
} |
444
|
|
|
|
445
|
|
|
/** |
446
|
|
|
* Get header/footer images. |
447
|
|
|
* |
448
|
|
|
* @return HeaderFooterDrawing[] |
449
|
|
|
*/ |
450
|
60 |
|
public function getImages() |
451
|
|
|
{ |
452
|
|
|
// Sort array |
453
|
60 |
|
$images = []; |
454
|
60 |
|
if (isset($this->headerFooterImages[self::IMAGE_HEADER_LEFT])) { |
455
|
1 |
|
$images[self::IMAGE_HEADER_LEFT] = $this->headerFooterImages[self::IMAGE_HEADER_LEFT]; |
456
|
|
|
} |
457
|
60 |
|
if (isset($this->headerFooterImages[self::IMAGE_HEADER_CENTER])) { |
458
|
|
|
$images[self::IMAGE_HEADER_CENTER] = $this->headerFooterImages[self::IMAGE_HEADER_CENTER]; |
459
|
|
|
} |
460
|
60 |
|
if (isset($this->headerFooterImages[self::IMAGE_HEADER_RIGHT])) { |
461
|
|
|
$images[self::IMAGE_HEADER_RIGHT] = $this->headerFooterImages[self::IMAGE_HEADER_RIGHT]; |
462
|
|
|
} |
463
|
60 |
|
if (isset($this->headerFooterImages[self::IMAGE_FOOTER_LEFT])) { |
464
|
|
|
$images[self::IMAGE_FOOTER_LEFT] = $this->headerFooterImages[self::IMAGE_FOOTER_LEFT]; |
465
|
|
|
} |
466
|
60 |
|
if (isset($this->headerFooterImages[self::IMAGE_FOOTER_CENTER])) { |
467
|
|
|
$images[self::IMAGE_FOOTER_CENTER] = $this->headerFooterImages[self::IMAGE_FOOTER_CENTER]; |
468
|
|
|
} |
469
|
60 |
|
if (isset($this->headerFooterImages[self::IMAGE_FOOTER_RIGHT])) { |
470
|
|
|
$images[self::IMAGE_FOOTER_RIGHT] = $this->headerFooterImages[self::IMAGE_FOOTER_RIGHT]; |
471
|
|
|
} |
472
|
60 |
|
$this->headerFooterImages = $images; |
473
|
|
|
|
474
|
60 |
|
return $this->headerFooterImages; |
475
|
|
|
} |
476
|
|
|
|
477
|
|
|
/** |
478
|
|
|
* Implement PHP __clone to create a deep clone, not just a shallow copy. |
479
|
|
|
*/ |
480
|
|
|
public function __clone() |
481
|
|
|
{ |
482
|
|
|
$vars = get_object_vars($this); |
483
|
|
|
foreach ($vars as $key => $value) { |
484
|
|
|
if (is_object($value)) { |
485
|
|
|
$this->$key = clone $value; |
486
|
|
|
} else { |
487
|
|
|
$this->$key = $value; |
488
|
|
|
} |
489
|
|
|
} |
490
|
|
|
} |
491
|
|
|
} |
492
|
|
|
|