PageRenderTime 34ms CodeModel.GetById 19ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 0ms

/PHPExcel/Worksheet/HeaderFooter.php

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