3 * PHPExcel_Worksheet_HeaderFooter
5 * Copyright (c) 2006 - 2015 PHPExcel
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not,241 write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 * @package PHPExcel_Worksheet
23 * @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
24 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
25 * @version ##VERSION##, ##DATE##
28 * Header/Footer Formatting Syntax taken from Office Open XML Part 4 - Markup Language Reference, page 1970:
30 * There are a number of formatting codes that can be written inline with the actual header / footer text, which
31 * affect the formatting in the header or footer.
33 * Example: This example shows the text "Center Bold Header" on the first line (center section), and the date on
34 * the second line (center section).
35 * &CCenter &"-,Bold"Bold&"-,Regular"Header_x000A_&D
38 * There is no required order in which these codes must appear.
40 * The first occurrence of the following codes turns the formatting ON, the second occurrence turns it OFF again:
44 * Superscript and subscript cannot both be ON at same time. Whichever comes first wins and the other is ignored,
45 * while the first is ON.
46 * &L - code for "left section" (there are three header / footer locations, "left", "center", and "right"). When
47 * two or more occurrences of this section marker exist, the contents from all markers are concatenated, in the
48 * order of appearance, and placed into the left section.
49 * &P - code for "current page #"
50 * &N - code for "total pages"
51 * &font size - code for "text font size", where font size is a font size in points.
52 * &K - code for "text font color"
53 * RGB Color is specified as RRGGBB
54 * Theme Color is specifed as TTSNN where TT is the theme color Id, S is either "+" or "-" of the tint/shade
55 * value, NN is the tint/shade value.
56 * &S - code for "text strikethrough" on / off
57 * &X - code for "text super script" on / off
58 * &Y - code for "text subscript" on / off
59 * &C - code for "center section". When two or more occurrences of this section marker exist, the contents
60 * from all markers are concatenated, in the order of appearance, and placed into the center section.
62 * &D - code for "date"
63 * &T - code for "time"
64 * &G - code for "picture as background"
65 * &U - code for "text single underline"
66 * &E - code for "double underline"
67 * &R - code for "right section". When two or more occurrences of this section marker exist, the contents
68 * from all markers are concatenated, in the order of appearance, and placed into the right section.
69 * &Z - code for "this workbook's file path"
70 * &F - code for "this workbook's file name"
71 * &A - code for "sheet tab name"
72 * &+ - code for add to page #.
73 * &- - code for subtract from page #.
74 * &"font name,font type" - code for "text font name" and "text font type", where font name and font type
75 * are strings specifying the name and type of the font, separated by a comma. When a hyphen appears in font
76 * name, it means "none specified". Both of font name and font type can be localized values.
77 * &"-,Bold" - code for "bold font style"
78 * &B - also means "bold font style".
79 * &"-,Regular" - code for "regular font style"
80 * &"-,Italic" - code for "italic font style"
81 * &I - also means "italic font style"
82 * &"-,Bold Italic" code for "bold italic font style"
83 * &O - code for "outline style"
84 * &H - code for "shadow style"
88 class PHPExcel_Worksheet_HeaderFooter
90 /* Header/footer image location */
91 const IMAGE_HEADER_LEFT
= 'LH';
92 const IMAGE_HEADER_CENTER
= 'CH';
93 const IMAGE_HEADER_RIGHT
= 'RH';
94 const IMAGE_FOOTER_LEFT
= 'LF';
95 const IMAGE_FOOTER_CENTER
= 'CF';
96 const IMAGE_FOOTER_RIGHT
= 'RF';
103 private $oddHeader = '';
110 private $oddFooter = '';
117 private $evenHeader = '';
124 private $evenFooter = '';
131 private $firstHeader = '';
138 private $firstFooter = '';
141 * Different header for Odd/Even, defaults to false
145 private $differentOddEven = false;
148 * Different header for first page, defaults to false
152 private $differentFirst = false;
155 * Scale with document, defaults to true
159 private $scaleWithDocument = true;
162 * Align with margins, defaults to true
166 private $alignWithMargins = true;
169 * Header/footer images
171 * @var PHPExcel_Worksheet_HeaderFooterDrawing[]
173 private $headerFooterImages = array();
176 * Create a new PHPExcel_Worksheet_HeaderFooter
178 public function __construct()
187 public function getOddHeader()
189 return $this->oddHeader
;
195 * @param string $pValue
196 * @return PHPExcel_Worksheet_HeaderFooter
198 public function setOddHeader($pValue)
200 $this->oddHeader
= $pValue;
209 public function getOddFooter()
211 return $this->oddFooter
;
217 * @param string $pValue
218 * @return PHPExcel_Worksheet_HeaderFooter
220 public function setOddFooter($pValue)
222 $this->oddFooter
= $pValue;
231 public function getEvenHeader()
233 return $this->evenHeader
;
239 * @param string $pValue
240 * @return PHPExcel_Worksheet_HeaderFooter
242 public function setEvenHeader($pValue)
244 $this->evenHeader
= $pValue;
253 public function getEvenFooter()
255 return $this->evenFooter
;
261 * @param string $pValue
262 * @return PHPExcel_Worksheet_HeaderFooter
264 public function setEvenFooter($pValue)
266 $this->evenFooter
= $pValue;
275 public function getFirstHeader()
277 return $this->firstHeader
;
283 * @param string $pValue
284 * @return PHPExcel_Worksheet_HeaderFooter
286 public function setFirstHeader($pValue)
288 $this->firstHeader
= $pValue;
297 public function getFirstFooter()
299 return $this->firstFooter
;
305 * @param string $pValue
306 * @return PHPExcel_Worksheet_HeaderFooter
308 public function setFirstFooter($pValue)
310 $this->firstFooter
= $pValue;
315 * Get DifferentOddEven
319 public function getDifferentOddEven()
321 return $this->differentOddEven
;
325 * Set DifferentOddEven
327 * @param boolean $pValue
328 * @return PHPExcel_Worksheet_HeaderFooter
330 public function setDifferentOddEven($pValue = false)
332 $this->differentOddEven
= $pValue;
341 public function getDifferentFirst()
343 return $this->differentFirst
;
349 * @param boolean $pValue
350 * @return PHPExcel_Worksheet_HeaderFooter
352 public function setDifferentFirst($pValue = false)
354 $this->differentFirst
= $pValue;
359 * Get ScaleWithDocument
363 public function getScaleWithDocument()
365 return $this->scaleWithDocument
;
369 * Set ScaleWithDocument
371 * @param boolean $pValue
372 * @return PHPExcel_Worksheet_HeaderFooter
374 public function setScaleWithDocument($pValue = true)
376 $this->scaleWithDocument
= $pValue;
381 * Get AlignWithMargins
385 public function getAlignWithMargins()
387 return $this->alignWithMargins
;
391 * Set AlignWithMargins
393 * @param boolean $pValue
394 * @return PHPExcel_Worksheet_HeaderFooter
396 public function setAlignWithMargins($pValue = true)
398 $this->alignWithMargins
= $pValue;
403 * Add header/footer image
405 * @param PHPExcel_Worksheet_HeaderFooterDrawing $image
406 * @param string $location
407 * @throws PHPExcel_Exception
408 * @return PHPExcel_Worksheet_HeaderFooter
410 public function addImage(PHPExcel_Worksheet_HeaderFooterDrawing
$image = null, $location = self
::IMAGE_HEADER_LEFT
)
412 $this->headerFooterImages
[$location] = $image;
417 * Remove header/footer image
419 * @param string $location
420 * @throws PHPExcel_Exception
421 * @return PHPExcel_Worksheet_HeaderFooter
423 public function removeImage($location = self
::IMAGE_HEADER_LEFT
)
425 if (isset($this->headerFooterImages
[$location])) {
426 unset($this->headerFooterImages
[$location]);
432 * Set header/footer images
434 * @param PHPExcel_Worksheet_HeaderFooterDrawing[] $images
435 * @throws PHPExcel_Exception
436 * @return PHPExcel_Worksheet_HeaderFooter
438 public function setImages($images)
440 if (!is_array($images)) {
441 throw new PHPExcel_Exception('Invalid parameter!');
444 $this->headerFooterImages
= $images;
449 * Get header/footer images
451 * @return PHPExcel_Worksheet_HeaderFooterDrawing[]
453 public function getImages()
457 if (isset($this->headerFooterImages
[self
::IMAGE_HEADER_LEFT
])) {
458 $images[self
::IMAGE_HEADER_LEFT
] = $this->headerFooterImages
[self
::IMAGE_HEADER_LEFT
];
460 if (isset($this->headerFooterImages
[self
::IMAGE_HEADER_CENTER
])) {
461 $images[self
::IMAGE_HEADER_CENTER
] = $this->headerFooterImages
[self
::IMAGE_HEADER_CENTER
];
463 if (isset($this->headerFooterImages
[self
::IMAGE_HEADER_RIGHT
])) {
464 $images[self
::IMAGE_HEADER_RIGHT
] = $this->headerFooterImages
[self
::IMAGE_HEADER_RIGHT
];
466 if (isset($this->headerFooterImages
[self
::IMAGE_FOOTER_LEFT
])) {
467 $images[self
::IMAGE_FOOTER_LEFT
] = $this->headerFooterImages
[self
::IMAGE_FOOTER_LEFT
];
469 if (isset($this->headerFooterImages
[self
::IMAGE_FOOTER_CENTER
])) {
470 $images[self
::IMAGE_FOOTER_CENTER
] = $this->headerFooterImages
[self
::IMAGE_FOOTER_CENTER
];
472 if (isset($this->headerFooterImages
[self
::IMAGE_FOOTER_RIGHT
])) {
473 $images[self
::IMAGE_FOOTER_RIGHT
] = $this->headerFooterImages
[self
::IMAGE_FOOTER_RIGHT
];
475 $this->headerFooterImages
= $images;
477 return $this->headerFooterImages
;
481 * Implement PHP __clone to create a deep clone, not just a shallow copy.
483 public function __clone()
485 $vars = get_object_vars($this);
486 foreach ($vars as $key => $value) {
487 if (is_object($value)) {
488 $this->$key = clone $value;
490 $this->$key = $value;