PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.0.3
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.0.3
4.0.8 4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.2 3.1.3 3.10.0 3.10.1 3.10.10 3.10.11 3.10.12 3.10.13 3.10.14 3.10.15 3.10.2 3.10.3 All 149 releases
visualizer / vendor / phpoffice / phpexcel / Classes / PHPExcel / Style / Alignment.php

Alignment.php in Visualizer – Tables & Charts Manager with Built-in AI Generator 3.0.3, at vendor/phpoffice/phpexcel/Classes/PHPExcel/Style/Alignment.php

460 lines 10.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * PHPExcel
4 *
5 * Copyright (c) 2006 - 2014 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 - 2014 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 - 2014 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 const HORIZONTAL_FILL = 'fill';
46 const HORIZONTAL_DISTRIBUTED = 'distributed'; // Excel2007 only
47
48 /* Vertical alignment styles */
49 const VERTICAL_BOTTOM = 'bottom';
50 const VERTICAL_TOP = 'top';
51 const VERTICAL_CENTER = 'center';
52 const VERTICAL_JUSTIFY = 'justify';
53 const VERTICAL_DISTRIBUTED = 'distributed'; // Excel2007 only
54
55 /* Read order */
56 const READORDER_CONTEXT = 0;
57 const READORDER_LTR = 1;
58 const READORDER_RTL = 2;
59
60 /**
61 * Horizontal alignment
62 *
63 * @var string
64 */
65 protected $_horizontal = PHPExcel_Style_Alignment::HORIZONTAL_GENERAL;
66
67 /**
68 * Vertical alignment
69 *
70 * @var string
71 */
72 protected $_vertical = PHPExcel_Style_Alignment::VERTICAL_BOTTOM;
73
74 /**
75 * Text rotation
76 *
77 * @var integer
78 */
79 protected $_textRotation = 0;
80
81 /**
82 * Wrap text
83 *
84 * @var boolean
85 */
86 protected $_wrapText = FALSE;
87
88 /**
89 * Shrink to fit
90 *
91 * @var boolean
92 */
93 protected $_shrinkToFit = FALSE;
94
95 /**
96 * Indent - only possible with horizontal alignment left and right
97 *
98 * @var integer
99 */
100 protected $_indent = 0;
101
102 /**
103 * Read order
104 *
105 * @var integer
106 */
107 protected $_readorder = 0;
108
109 /**
110 * Create a new PHPExcel_Style_Alignment
111 *
112 * @param boolean $isSupervisor Flag indicating if this is a supervisor or not
113 * Leave this value at default unless you understand exactly what
114 * its ramifications are
115 * @param boolean $isConditional Flag indicating if this is a conditional style or not
116 * Leave this value at default unless you understand exactly what
117 * its ramifications are
118 */
119 public function __construct($isSupervisor = FALSE, $isConditional = FALSE)
120 {
121 // Supervisor?
122 parent::__construct($isSupervisor);
123
124 if ($isConditional) {
125 $this->_horizontal = NULL;
126 $this->_vertical = NULL;
127 $this->_textRotation = NULL;
128 }
129 }
130
131 /**
132 * Get the shared style component for the currently active cell in currently active sheet.
133 * Only used for style supervisor
134 *
135 * @return PHPExcel_Style_Alignment
136 */
137 public function getSharedComponent()
138 {
139 return $this->_parent->getSharedComponent()->getAlignment();
140 }
141
142 /**
143 * Build style array from subcomponents
144 *
145 * @param array $array
146 * @return array
147 */
148 public function getStyleArray($array)
149 {
150 return array('alignment' => $array);
151 }
152
153 /**
154 * Apply styles from array
155 *
156 * <code>
157 * $objPHPExcel->getActiveSheet()->getStyle('B2')->getAlignment()->applyFromArray(
158 * array(
159 * 'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
160 * 'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
161 * 'rotation' => 0,
162 * 'wrap' => TRUE
163 * )
164 * );
165 * </code>
166 *
167 * @param array $pStyles Array containing style information
168 * @throws PHPExcel_Exception
169 * @return PHPExcel_Style_Alignment
170 */
171 public function applyFromArray($pStyles = NULL) {
172 if (is_array($pStyles)) {
173 if ($this->_isSupervisor) {
174 $this->getActiveSheet()->getStyle($this->getSelectedCells())
175 ->applyFromArray($this->getStyleArray($pStyles));
176 } else {
177 if (isset($pStyles['horizontal'])) {
178 $this->setHorizontal($pStyles['horizontal']);
179 }
180 if (isset($pStyles['vertical'])) {
181 $this->setVertical($pStyles['vertical']);
182 }
183 if (isset($pStyles['rotation'])) {
184 $this->setTextRotation($pStyles['rotation']);
185 }
186 if (isset($pStyles['wrap'])) {
187 $this->setWrapText($pStyles['wrap']);
188 }
189 if (isset($pStyles['shrinkToFit'])) {
190 $this->setShrinkToFit($pStyles['shrinkToFit']);
191 }
192 if (isset($pStyles['indent'])) {
193 $this->setIndent($pStyles['indent']);
194 }
195 if (isset($pStyles['readorder'])) {
196 $this->setReadorder($pStyles['readorder']);
197 }
198 }
199 } else {
200 throw new PHPExcel_Exception("Invalid style array passed.");
201 }
202 return $this;
203 }
204
205 /**
206 * Get Horizontal
207 *
208 * @return string
209 */
210 public function getHorizontal() {
211 if ($this->_isSupervisor) {
212 return $this->getSharedComponent()->getHorizontal();
213 }
214 return $this->_horizontal;
215 }
216
217 /**
218 * Set Horizontal
219 *
220 * @param string $pValue
221 * @return PHPExcel_Style_Alignment
222 */
223 public function setHorizontal($pValue = PHPExcel_Style_Alignment::HORIZONTAL_GENERAL) {
224 if ($pValue == '') {
225 $pValue = PHPExcel_Style_Alignment::HORIZONTAL_GENERAL;
226 }
227
228 if ($this->_isSupervisor) {
229 $styleArray = $this->getStyleArray(array('horizontal' => $pValue));
230 $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
231 }
232 else {
233 $this->_horizontal = $pValue;
234 }
235 return $this;
236 }
237
238 /**
239 * Get Vertical
240 *
241 * @return string
242 */
243 public function getVertical() {
244 if ($this->_isSupervisor) {
245 return $this->getSharedComponent()->getVertical();
246 }
247 return $this->_vertical;
248 }
249
250 /**
251 * Set Vertical
252 *
253 * @param string $pValue
254 * @return PHPExcel_Style_Alignment
255 */
256 public function setVertical($pValue = PHPExcel_Style_Alignment::VERTICAL_BOTTOM) {
257 if ($pValue == '') {
258 $pValue = PHPExcel_Style_Alignment::VERTICAL_BOTTOM;
259 }
260
261 if ($this->_isSupervisor) {
262 $styleArray = $this->getStyleArray(array('vertical' => $pValue));
263 $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
264 } else {
265 $this->_vertical = $pValue;
266 }
267 return $this;
268 }
269
270 /**
271 * Get TextRotation
272 *
273 * @return int
274 */
275 public function getTextRotation() {
276 if ($this->_isSupervisor) {
277 return $this->getSharedComponent()->getTextRotation();
278 }
279 return $this->_textRotation;
280 }
281
282 /**
283 * Set TextRotation
284 *
285 * @param int $pValue
286 * @throws PHPExcel_Exception
287 * @return PHPExcel_Style_Alignment
288 */
289 public function setTextRotation($pValue = 0) {
290 // Excel2007 value 255 => PHPExcel value -165
291 if ($pValue == 255) {
292 $pValue = -165;
293 }
294
295 // Set rotation
296 if ( ($pValue >= -90 && $pValue <= 90) || $pValue == -165 ) {
297 if ($this->_isSupervisor) {
298 $styleArray = $this->getStyleArray(array('rotation' => $pValue));
299 $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
300 } else {
301 $this->_textRotation = $pValue;
302 }
303 } else {
304 throw new PHPExcel_Exception("Text rotation should be a value between -90 and 90.");
305 }
306
307 return $this;
308 }
309
310 /**
311 * Get Wrap Text
312 *
313 * @return boolean
314 */
315 public function getWrapText() {
316 if ($this->_isSupervisor) {
317 return $this->getSharedComponent()->getWrapText();
318 }
319 return $this->_wrapText;
320 }
321
322 /**
323 * Set Wrap Text
324 *
325 * @param boolean $pValue
326 * @return PHPExcel_Style_Alignment
327 */
328 public function setWrapText($pValue = FALSE) {
329 if ($pValue == '') {
330 $pValue = FALSE;
331 }
332 if ($this->_isSupervisor) {
333 $styleArray = $this->getStyleArray(array('wrap' => $pValue));
334 $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
335 } else {
336 $this->_wrapText = $pValue;
337 }
338 return $this;
339 }
340
341 /**
342 * Get Shrink to fit
343 *
344 * @return boolean
345 */
346 public function getShrinkToFit() {
347 if ($this->_isSupervisor) {
348 return $this->getSharedComponent()->getShrinkToFit();
349 }
350 return $this->_shrinkToFit;
351 }
352
353 /**
354 * Set Shrink to fit
355 *
356 * @param boolean $pValue
357 * @return PHPExcel_Style_Alignment
358 */
359 public function setShrinkToFit($pValue = FALSE) {
360 if ($pValue == '') {
361 $pValue = FALSE;
362 }
363 if ($this->_isSupervisor) {
364 $styleArray = $this->getStyleArray(array('shrinkToFit' => $pValue));
365 $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
366 } else {
367 $this->_shrinkToFit = $pValue;
368 }
369 return $this;
370 }
371
372 /**
373 * Get indent
374 *
375 * @return int
376 */
377 public function getIndent() {
378 if ($this->_isSupervisor) {
379 return $this->getSharedComponent()->getIndent();
380 }
381 return $this->_indent;
382 }
383
384 /**
385 * Set indent
386 *
387 * @param int $pValue
388 * @return PHPExcel_Style_Alignment
389 */
390 public function setIndent($pValue = 0) {
391 if ($pValue > 0) {
392 if ($this->getHorizontal() != self::HORIZONTAL_GENERAL &&
393 $this->getHorizontal() != self::HORIZONTAL_LEFT &&
394 $this->getHorizontal() != self::HORIZONTAL_RIGHT) {
395 $pValue = 0; // indent not supported
396 }
397 }
398 if ($this->_isSupervisor) {
399 $styleArray = $this->getStyleArray(array('indent' => $pValue));
400 $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
401 } else {
402 $this->_indent = $pValue;
403 }
404 return $this;
405 }
406
407 /**
408 * Get read order
409 *
410 * @return integer
411 */
412 public function getReadorder() {
413 if ($this->_isSupervisor) {
414 return $this->getSharedComponent()->getReadorder();
415 }
416 return $this->_readorder;
417 }
418
419 /**
420 * Set read order
421 *
422 * @param int $pValue
423 * @return PHPExcel_Style_Alignment
424 */
425 public function setReadorder($pValue = 0) {
426 if ($pValue < 0 || $pValue > 2) {
427 $pValue = 0;
428 }
429 if ($this->_isSupervisor) {
430 $styleArray = $this->getStyleArray(array('readorder' => $pValue));
431 $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
432 } else {
433 $this->_readorder = $pValue;
434 }
435 return $this;
436 }
437
438 /**
439 * Get hash code
440 *
441 * @return string Hash code
442 */
443 public function getHashCode() {
444 if ($this->_isSupervisor) {
445 return $this->getSharedComponent()->getHashCode();
446 }
447 return md5(
448 $this->_horizontal
449 . $this->_vertical
450 . $this->_textRotation
451 . ($this->_wrapText ? 't' : 'f')
452 . ($this->_shrinkToFit ? 't' : 'f')
453 . $this->_indent
454 . $this->_readorder
455 . __CLASS__
456 );
457 }
458
459 }
460