Subversion Repositories eFlore/Applications.cel

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2388 jpm 1
<?php
2
/**
3
 * PHPExcel
4
 *
5
 * Copyright (c) 2006 - 2013 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_Style
23
 * @copyright  Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
24
 * @license	http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt	LGPL
25
 * @version	##VERSION##, ##DATE##
26
 */
27
 
28
 
29
/**
30
 * PHPExcel_Style_Alignment
31
 *
32
 * @category   PHPExcel
33
 * @package	PHPExcel_Style
34
 * @copyright  Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
35
 */
36
class PHPExcel_Style_Alignment extends PHPExcel_Style_Supervisor implements PHPExcel_IComparable
37
{
38
	/* Horizontal alignment styles */
39
	const HORIZONTAL_GENERAL				= 'general';
40
	const HORIZONTAL_LEFT					= 'left';
41
	const HORIZONTAL_RIGHT					= 'right';
42
	const HORIZONTAL_CENTER					= 'center';
43
	const HORIZONTAL_CENTER_CONTINUOUS		= 'centerContinuous';
44
	const HORIZONTAL_JUSTIFY				= 'justify';
45
 
46
	/* Vertical alignment styles */
47
	const VERTICAL_BOTTOM					= 'bottom';
48
	const VERTICAL_TOP						= 'top';
49
	const VERTICAL_CENTER					= 'center';
50
	const VERTICAL_JUSTIFY					= 'justify';
51
 
52
	/**
53
	 * Horizontal
54
	 *
55
	 * @var string
56
	 */
57
	protected $_horizontal	= PHPExcel_Style_Alignment::HORIZONTAL_GENERAL;
58
 
59
	/**
60
	 * Vertical
61
	 *
62
	 * @var string
63
	 */
64
	protected $_vertical		= PHPExcel_Style_Alignment::VERTICAL_BOTTOM;
65
 
66
	/**
67
	 * Text rotation
68
	 *
69
	 * @var int
70
	 */
71
	protected $_textRotation	= 0;
72
 
73
	/**
74
	 * Wrap text
75
	 *
76
	 * @var boolean
77
	 */
78
	protected $_wrapText		= FALSE;
79
 
80
	/**
81
	 * Shrink to fit
82
	 *
83
	 * @var boolean
84
	 */
85
	protected $_shrinkToFit	= FALSE;
86
 
87
	/**
88
	 * Indent - only possible with horizontal alignment left and right
89
	 *
90
	 * @var int
91
	 */
92
	protected $_indent		= 0;
93
 
94
	/**
95
	 * Create a new PHPExcel_Style_Alignment
96
	 *
97
	 * @param	boolean	$isSupervisor	Flag indicating if this is a supervisor or not
98
	 *									Leave this value at default unless you understand exactly what
99
	 *										its ramifications are
100
	 * @param	boolean	$isConditional	Flag indicating if this is a conditional style or not
101
	 *									Leave this value at default unless you understand exactly what
102
	 *										its ramifications are
103
	 */
104
	public function __construct($isSupervisor = FALSE, $isConditional = FALSE)
105
	{
106
		// Supervisor?
107
		parent::__construct($isSupervisor);
108
 
109
		if ($isConditional) {
110
			$this->_horizontal		= NULL;
111
			$this->_vertical		= NULL;
112
			$this->_textRotation	= NULL;
113
		}
114
	}
115
 
116
	/**
117
	 * Get the shared style component for the currently active cell in currently active sheet.
118
	 * Only used for style supervisor
119
	 *
120
	 * @return PHPExcel_Style_Alignment
121
	 */
122
	public function getSharedComponent()
123
	{
124
		return $this->_parent->getSharedComponent()->getAlignment();
125
	}
126
 
127
	/**
128
	 * Build style array from subcomponents
129
	 *
130
	 * @param array $array
131
	 * @return array
132
	 */
133
	public function getStyleArray($array)
134
	{
135
		return array('alignment' => $array);
136
	}
137
 
138
	/**
139
	 * Apply styles from array
140
	 *
141
	 * <code>
142
	 * $objPHPExcel->getActiveSheet()->getStyle('B2')->getAlignment()->applyFromArray(
143
	 *		array(
144
	 *			'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
145
	 *			'vertical'   => PHPExcel_Style_Alignment::VERTICAL_CENTER,
146
	 *			'rotation'   => 0,
147
	 *			'wrap'			=> TRUE
148
	 *		)
149
	 * );
150
	 * </code>
151
	 *
152
	 * @param	array	$pStyles	Array containing style information
153
	 * @throws	PHPExcel_Exception
154
	 * @return PHPExcel_Style_Alignment
155
	 */
156
	public function applyFromArray($pStyles = NULL) {
157
		if (is_array($pStyles)) {
158
			if ($this->_isSupervisor) {
159
				$this->getActiveSheet()->getStyle($this->getSelectedCells())
160
				    ->applyFromArray($this->getStyleArray($pStyles));
161
			} else {
162
				if (isset($pStyles['horizontal'])) {
163
					$this->setHorizontal($pStyles['horizontal']);
164
				}
165
				if (isset($pStyles['vertical'])) {
166
					$this->setVertical($pStyles['vertical']);
167
				}
168
				if (isset($pStyles['rotation'])) {
169
					$this->setTextRotation($pStyles['rotation']);
170
				}
171
				if (isset($pStyles['wrap'])) {
172
					$this->setWrapText($pStyles['wrap']);
173
				}
174
				if (isset($pStyles['shrinkToFit'])) {
175
					$this->setShrinkToFit($pStyles['shrinkToFit']);
176
				}
177
				if (isset($pStyles['indent'])) {
178
					$this->setIndent($pStyles['indent']);
179
				}
180
			}
181
		} else {
182
			throw new PHPExcel_Exception("Invalid style array passed.");
183
		}
184
		return $this;
185
	}
186
 
187
	/**
188
	 * Get Horizontal
189
	 *
190
	 * @return string
191
	 */
192
	public function getHorizontal() {
193
		if ($this->_isSupervisor) {
194
			return $this->getSharedComponent()->getHorizontal();
195
		}
196
		return $this->_horizontal;
197
	}
198
 
199
	/**
200
	 * Set Horizontal
201
	 *
202
	 * @param string $pValue
203
	 * @return PHPExcel_Style_Alignment
204
	 */
205
	public function setHorizontal($pValue = PHPExcel_Style_Alignment::HORIZONTAL_GENERAL) {
206
		if ($pValue == '') {
207
			$pValue = PHPExcel_Style_Alignment::HORIZONTAL_GENERAL;
208
		}
209
 
210
		if ($this->_isSupervisor) {
211
			$styleArray = $this->getStyleArray(array('horizontal' => $pValue));
212
			$this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
213
		}
214
		else {
215
			$this->_horizontal = $pValue;
216
		}
217
		return $this;
218
	}
219
 
220
	/**
221
	 * Get Vertical
222
	 *
223
	 * @return string
224
	 */
225
	public function getVertical() {
226
		if ($this->_isSupervisor) {
227
			return $this->getSharedComponent()->getVertical();
228
		}
229
		return $this->_vertical;
230
	}
231
 
232
	/**
233
	 * Set Vertical
234
	 *
235
	 * @param string $pValue
236
	 * @return PHPExcel_Style_Alignment
237
	 */
238
	public function setVertical($pValue = PHPExcel_Style_Alignment::VERTICAL_BOTTOM) {
239
		if ($pValue == '') {
240
			$pValue = PHPExcel_Style_Alignment::VERTICAL_BOTTOM;
241
		}
242
 
243
		if ($this->_isSupervisor) {
244
			$styleArray = $this->getStyleArray(array('vertical' => $pValue));
245
			$this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
246
		} else {
247
			$this->_vertical = $pValue;
248
		}
249
		return $this;
250
	}
251
 
252
	/**
253
	 * Get TextRotation
254
	 *
255
	 * @return int
256
	 */
257
	public function getTextRotation() {
258
		if ($this->_isSupervisor) {
259
			return $this->getSharedComponent()->getTextRotation();
260
		}
261
		return $this->_textRotation;
262
	}
263
 
264
	/**
265
	 * Set TextRotation
266
	 *
267
	 * @param int $pValue
268
	 * @throws PHPExcel_Exception
269
	 * @return PHPExcel_Style_Alignment
270
	 */
271
	public function setTextRotation($pValue = 0) {
272
		// Excel2007 value 255 => PHPExcel value -165
273
		if ($pValue == 255) {
274
			$pValue = -165;
275
		}
276
 
277
		// Set rotation
278
		if ( ($pValue >= -90 && $pValue <= 90) || $pValue == -165 ) {
279
			if ($this->_isSupervisor) {
280
				$styleArray = $this->getStyleArray(array('rotation' => $pValue));
281
				$this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
282
			} else {
283
				$this->_textRotation = $pValue;
284
			}
285
		} else {
286
			throw new PHPExcel_Exception("Text rotation should be a value between -90 and 90.");
287
		}
288
 
289
		return $this;
290
	}
291
 
292
	/**
293
	 * Get Wrap Text
294
	 *
295
	 * @return boolean
296
	 */
297
	public function getWrapText() {
298
		if ($this->_isSupervisor) {
299
			return $this->getSharedComponent()->getWrapText();
300
		}
301
		return $this->_wrapText;
302
	}
303
 
304
	/**
305
	 * Set Wrap Text
306
	 *
307
	 * @param boolean $pValue
308
	 * @return PHPExcel_Style_Alignment
309
	 */
310
	public function setWrapText($pValue = FALSE) {
311
		if ($pValue == '') {
312
			$pValue = FALSE;
313
		}
314
		if ($this->_isSupervisor) {
315
			$styleArray = $this->getStyleArray(array('wrap' => $pValue));
316
			$this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
317
		} else {
318
			$this->_wrapText = $pValue;
319
		}
320
		return $this;
321
	}
322
 
323
	/**
324
	 * Get Shrink to fit
325
	 *
326
	 * @return boolean
327
	 */
328
	public function getShrinkToFit() {
329
		if ($this->_isSupervisor) {
330
			return $this->getSharedComponent()->getShrinkToFit();
331
		}
332
		return $this->_shrinkToFit;
333
	}
334
 
335
	/**
336
	 * Set Shrink to fit
337
	 *
338
	 * @param boolean $pValue
339
	 * @return PHPExcel_Style_Alignment
340
	 */
341
	public function setShrinkToFit($pValue = FALSE) {
342
		if ($pValue == '') {
343
			$pValue = FALSE;
344
		}
345
		if ($this->_isSupervisor) {
346
			$styleArray = $this->getStyleArray(array('shrinkToFit' => $pValue));
347
			$this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
348
		} else {
349
			$this->_shrinkToFit = $pValue;
350
		}
351
		return $this;
352
	}
353
 
354
	/**
355
	 * Get indent
356
	 *
357
	 * @return int
358
	 */
359
	public function getIndent() {
360
		if ($this->_isSupervisor) {
361
			return $this->getSharedComponent()->getIndent();
362
		}
363
		return $this->_indent;
364
	}
365
 
366
	/**
367
	 * Set indent
368
	 *
369
	 * @param int $pValue
370
	 * @return PHPExcel_Style_Alignment
371
	 */
372
	public function setIndent($pValue = 0) {
373
		if ($pValue > 0) {
374
			if ($this->getHorizontal() != self::HORIZONTAL_GENERAL &&
375
				$this->getHorizontal() != self::HORIZONTAL_LEFT &&
376
				$this->getHorizontal() != self::HORIZONTAL_RIGHT) {
377
				$pValue = 0; // indent not supported
378
			}
379
		}
380
		if ($this->_isSupervisor) {
381
			$styleArray = $this->getStyleArray(array('indent' => $pValue));
382
			$this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
383
		} else {
384
			$this->_indent = $pValue;
385
		}
386
		return $this;
387
	}
388
 
389
	/**
390
	 * Get hash code
391
	 *
392
	 * @return string	Hash code
393
	 */
394
	public function getHashCode() {
395
		if ($this->_isSupervisor) {
396
			return $this->getSharedComponent()->getHashCode();
397
		}
398
		return md5(
399
			  $this->_horizontal
400
			. $this->_vertical
401
			. $this->_textRotation
402
			. ($this->_wrapText ? 't' : 'f')
403
			. ($this->_shrinkToFit ? 't' : 'f')
404
			. $this->_indent
405
			. __CLASS__
406
		);
407
	}
408
 
409
}