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 1.8.0, 2014-03-02 |
---|
26 | */ |
---|
27 | |
---|
28 | |
---|
29 | /** |
---|
30 | * PHPExcel_Style_Borders |
---|
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_Borders extends PHPExcel_Style_Supervisor implements PHPExcel_IComparable |
---|
37 | { |
---|
38 | /* Diagonal directions */ |
---|
39 | const DIAGONAL_NONE = 0; |
---|
40 | const DIAGONAL_UP = 1; |
---|
41 | const DIAGONAL_DOWN = 2; |
---|
42 | const DIAGONAL_BOTH = 3; |
---|
43 | |
---|
44 | /** |
---|
45 | * Left |
---|
46 | * |
---|
47 | * @var PHPExcel_Style_Border |
---|
48 | */ |
---|
49 | protected $_left; |
---|
50 | |
---|
51 | /** |
---|
52 | * Right |
---|
53 | * |
---|
54 | * @var PHPExcel_Style_Border |
---|
55 | */ |
---|
56 | protected $_right; |
---|
57 | |
---|
58 | /** |
---|
59 | * Top |
---|
60 | * |
---|
61 | * @var PHPExcel_Style_Border |
---|
62 | */ |
---|
63 | protected $_top; |
---|
64 | |
---|
65 | /** |
---|
66 | * Bottom |
---|
67 | * |
---|
68 | * @var PHPExcel_Style_Border |
---|
69 | */ |
---|
70 | protected $_bottom; |
---|
71 | |
---|
72 | /** |
---|
73 | * Diagonal |
---|
74 | * |
---|
75 | * @var PHPExcel_Style_Border |
---|
76 | */ |
---|
77 | protected $_diagonal; |
---|
78 | |
---|
79 | /** |
---|
80 | * DiagonalDirection |
---|
81 | * |
---|
82 | * @var int |
---|
83 | */ |
---|
84 | protected $_diagonalDirection; |
---|
85 | |
---|
86 | /** |
---|
87 | * All borders psedo-border. Only applies to supervisor. |
---|
88 | * |
---|
89 | * @var PHPExcel_Style_Border |
---|
90 | */ |
---|
91 | protected $_allBorders; |
---|
92 | |
---|
93 | /** |
---|
94 | * Outline psedo-border. Only applies to supervisor. |
---|
95 | * |
---|
96 | * @var PHPExcel_Style_Border |
---|
97 | */ |
---|
98 | protected $_outline; |
---|
99 | |
---|
100 | /** |
---|
101 | * Inside psedo-border. Only applies to supervisor. |
---|
102 | * |
---|
103 | * @var PHPExcel_Style_Border |
---|
104 | */ |
---|
105 | protected $_inside; |
---|
106 | |
---|
107 | /** |
---|
108 | * Vertical pseudo-border. Only applies to supervisor. |
---|
109 | * |
---|
110 | * @var PHPExcel_Style_Border |
---|
111 | */ |
---|
112 | protected $_vertical; |
---|
113 | |
---|
114 | /** |
---|
115 | * Horizontal pseudo-border. Only applies to supervisor. |
---|
116 | * |
---|
117 | * @var PHPExcel_Style_Border |
---|
118 | */ |
---|
119 | protected $_horizontal; |
---|
120 | |
---|
121 | /** |
---|
122 | * Create a new PHPExcel_Style_Borders |
---|
123 | * |
---|
124 | * @param boolean $isSupervisor Flag indicating if this is a supervisor or not |
---|
125 | * Leave this value at default unless you understand exactly what |
---|
126 | * its ramifications are |
---|
127 | * @param boolean $isConditional Flag indicating if this is a conditional style or not |
---|
128 | * Leave this value at default unless you understand exactly what |
---|
129 | * its ramifications are |
---|
130 | */ |
---|
131 | public function __construct($isSupervisor = FALSE, $isConditional = FALSE) |
---|
132 | { |
---|
133 | // Supervisor? |
---|
134 | parent::__construct($isSupervisor); |
---|
135 | |
---|
136 | // Initialise values |
---|
137 | $this->_left = new PHPExcel_Style_Border($isSupervisor, $isConditional); |
---|
138 | $this->_right = new PHPExcel_Style_Border($isSupervisor, $isConditional); |
---|
139 | $this->_top = new PHPExcel_Style_Border($isSupervisor, $isConditional); |
---|
140 | $this->_bottom = new PHPExcel_Style_Border($isSupervisor, $isConditional); |
---|
141 | $this->_diagonal = new PHPExcel_Style_Border($isSupervisor, $isConditional); |
---|
142 | $this->_diagonalDirection = PHPExcel_Style_Borders::DIAGONAL_NONE; |
---|
143 | |
---|
144 | // Specially for supervisor |
---|
145 | if ($isSupervisor) { |
---|
146 | // Initialize pseudo-borders |
---|
147 | $this->_allBorders = new PHPExcel_Style_Border(TRUE); |
---|
148 | $this->_outline = new PHPExcel_Style_Border(TRUE); |
---|
149 | $this->_inside = new PHPExcel_Style_Border(TRUE); |
---|
150 | $this->_vertical = new PHPExcel_Style_Border(TRUE); |
---|
151 | $this->_horizontal = new PHPExcel_Style_Border(TRUE); |
---|
152 | |
---|
153 | // bind parent if we are a supervisor |
---|
154 | $this->_left->bindParent($this, '_left'); |
---|
155 | $this->_right->bindParent($this, '_right'); |
---|
156 | $this->_top->bindParent($this, '_top'); |
---|
157 | $this->_bottom->bindParent($this, '_bottom'); |
---|
158 | $this->_diagonal->bindParent($this, '_diagonal'); |
---|
159 | $this->_allBorders->bindParent($this, '_allBorders'); |
---|
160 | $this->_outline->bindParent($this, '_outline'); |
---|
161 | $this->_inside->bindParent($this, '_inside'); |
---|
162 | $this->_vertical->bindParent($this, '_vertical'); |
---|
163 | $this->_horizontal->bindParent($this, '_horizontal'); |
---|
164 | } |
---|
165 | } |
---|
166 | |
---|
167 | /** |
---|
168 | * Get the shared style component for the currently active cell in currently active sheet. |
---|
169 | * Only used for style supervisor |
---|
170 | * |
---|
171 | * @return PHPExcel_Style_Borders |
---|
172 | */ |
---|
173 | public function getSharedComponent() |
---|
174 | { |
---|
175 | return $this->_parent->getSharedComponent()->getBorders(); |
---|
176 | } |
---|
177 | |
---|
178 | /** |
---|
179 | * Build style array from subcomponents |
---|
180 | * |
---|
181 | * @param array $array |
---|
182 | * @return array |
---|
183 | */ |
---|
184 | public function getStyleArray($array) |
---|
185 | { |
---|
186 | return array('borders' => $array); |
---|
187 | } |
---|
188 | |
---|
189 | /** |
---|
190 | * Apply styles from array |
---|
191 | * |
---|
192 | * <code> |
---|
193 | * $objPHPExcel->getActiveSheet()->getStyle('B2')->getBorders()->applyFromArray( |
---|
194 | * array( |
---|
195 | * 'bottom' => array( |
---|
196 | * 'style' => PHPExcel_Style_Border::BORDER_DASHDOT, |
---|
197 | * 'color' => array( |
---|
198 | * 'rgb' => '808080' |
---|
199 | * ) |
---|
200 | * ), |
---|
201 | * 'top' => array( |
---|
202 | * 'style' => PHPExcel_Style_Border::BORDER_DASHDOT, |
---|
203 | * 'color' => array( |
---|
204 | * 'rgb' => '808080' |
---|
205 | * ) |
---|
206 | * ) |
---|
207 | * ) |
---|
208 | * ); |
---|
209 | * </code> |
---|
210 | * <code> |
---|
211 | * $objPHPExcel->getActiveSheet()->getStyle('B2')->getBorders()->applyFromArray( |
---|
212 | * array( |
---|
213 | * 'allborders' => array( |
---|
214 | * 'style' => PHPExcel_Style_Border::BORDER_DASHDOT, |
---|
215 | * 'color' => array( |
---|
216 | * 'rgb' => '808080' |
---|
217 | * ) |
---|
218 | * ) |
---|
219 | * ) |
---|
220 | * ); |
---|
221 | * </code> |
---|
222 | * |
---|
223 | * @param array $pStyles Array containing style information |
---|
224 | * @throws PHPExcel_Exception |
---|
225 | * @return PHPExcel_Style_Borders |
---|
226 | */ |
---|
227 | public function applyFromArray($pStyles = null) { |
---|
228 | if (is_array($pStyles)) { |
---|
229 | if ($this->_isSupervisor) { |
---|
230 | $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($this->getStyleArray($pStyles)); |
---|
231 | } else { |
---|
232 | if (array_key_exists('left', $pStyles)) { |
---|
233 | $this->getLeft()->applyFromArray($pStyles['left']); |
---|
234 | } |
---|
235 | if (array_key_exists('right', $pStyles)) { |
---|
236 | $this->getRight()->applyFromArray($pStyles['right']); |
---|
237 | } |
---|
238 | if (array_key_exists('top', $pStyles)) { |
---|
239 | $this->getTop()->applyFromArray($pStyles['top']); |
---|
240 | } |
---|
241 | if (array_key_exists('bottom', $pStyles)) { |
---|
242 | $this->getBottom()->applyFromArray($pStyles['bottom']); |
---|
243 | } |
---|
244 | if (array_key_exists('diagonal', $pStyles)) { |
---|
245 | $this->getDiagonal()->applyFromArray($pStyles['diagonal']); |
---|
246 | } |
---|
247 | if (array_key_exists('diagonaldirection', $pStyles)) { |
---|
248 | $this->setDiagonalDirection($pStyles['diagonaldirection']); |
---|
249 | } |
---|
250 | if (array_key_exists('allborders', $pStyles)) { |
---|
251 | $this->getLeft()->applyFromArray($pStyles['allborders']); |
---|
252 | $this->getRight()->applyFromArray($pStyles['allborders']); |
---|
253 | $this->getTop()->applyFromArray($pStyles['allborders']); |
---|
254 | $this->getBottom()->applyFromArray($pStyles['allborders']); |
---|
255 | } |
---|
256 | } |
---|
257 | } else { |
---|
258 | throw new PHPExcel_Exception("Invalid style array passed."); |
---|
259 | } |
---|
260 | return $this; |
---|
261 | } |
---|
262 | |
---|
263 | /** |
---|
264 | * Get Left |
---|
265 | * |
---|
266 | * @return PHPExcel_Style_Border |
---|
267 | */ |
---|
268 | public function getLeft() { |
---|
269 | return $this->_left; |
---|
270 | } |
---|
271 | |
---|
272 | /** |
---|
273 | * Get Right |
---|
274 | * |
---|
275 | * @return PHPExcel_Style_Border |
---|
276 | */ |
---|
277 | public function getRight() { |
---|
278 | return $this->_right; |
---|
279 | } |
---|
280 | |
---|
281 | /** |
---|
282 | * Get Top |
---|
283 | * |
---|
284 | * @return PHPExcel_Style_Border |
---|
285 | */ |
---|
286 | public function getTop() { |
---|
287 | return $this->_top; |
---|
288 | } |
---|
289 | |
---|
290 | /** |
---|
291 | * Get Bottom |
---|
292 | * |
---|
293 | * @return PHPExcel_Style_Border |
---|
294 | */ |
---|
295 | public function getBottom() { |
---|
296 | return $this->_bottom; |
---|
297 | } |
---|
298 | |
---|
299 | /** |
---|
300 | * Get Diagonal |
---|
301 | * |
---|
302 | * @return PHPExcel_Style_Border |
---|
303 | */ |
---|
304 | public function getDiagonal() { |
---|
305 | return $this->_diagonal; |
---|
306 | } |
---|
307 | |
---|
308 | /** |
---|
309 | * Get AllBorders (pseudo-border). Only applies to supervisor. |
---|
310 | * |
---|
311 | * @return PHPExcel_Style_Border |
---|
312 | * @throws PHPExcel_Exception |
---|
313 | */ |
---|
314 | public function getAllBorders() { |
---|
315 | if (!$this->_isSupervisor) { |
---|
316 | throw new PHPExcel_Exception('Can only get pseudo-border for supervisor.'); |
---|
317 | } |
---|
318 | return $this->_allBorders; |
---|
319 | } |
---|
320 | |
---|
321 | /** |
---|
322 | * Get Outline (pseudo-border). Only applies to supervisor. |
---|
323 | * |
---|
324 | * @return boolean |
---|
325 | * @throws PHPExcel_Exception |
---|
326 | */ |
---|
327 | public function getOutline() { |
---|
328 | if (!$this->_isSupervisor) { |
---|
329 | throw new PHPExcel_Exception('Can only get pseudo-border for supervisor.'); |
---|
330 | } |
---|
331 | return $this->_outline; |
---|
332 | } |
---|
333 | |
---|
334 | /** |
---|
335 | * Get Inside (pseudo-border). Only applies to supervisor. |
---|
336 | * |
---|
337 | * @return boolean |
---|
338 | * @throws PHPExcel_Exception |
---|
339 | */ |
---|
340 | public function getInside() { |
---|
341 | if (!$this->_isSupervisor) { |
---|
342 | throw new PHPExcel_Exception('Can only get pseudo-border for supervisor.'); |
---|
343 | } |
---|
344 | return $this->_inside; |
---|
345 | } |
---|
346 | |
---|
347 | /** |
---|
348 | * Get Vertical (pseudo-border). Only applies to supervisor. |
---|
349 | * |
---|
350 | * @return PHPExcel_Style_Border |
---|
351 | * @throws PHPExcel_Exception |
---|
352 | */ |
---|
353 | public function getVertical() { |
---|
354 | if (!$this->_isSupervisor) { |
---|
355 | throw new PHPExcel_Exception('Can only get pseudo-border for supervisor.'); |
---|
356 | } |
---|
357 | return $this->_vertical; |
---|
358 | } |
---|
359 | |
---|
360 | /** |
---|
361 | * Get Horizontal (pseudo-border). Only applies to supervisor. |
---|
362 | * |
---|
363 | * @return PHPExcel_Style_Border |
---|
364 | * @throws PHPExcel_Exception |
---|
365 | */ |
---|
366 | public function getHorizontal() { |
---|
367 | if (!$this->_isSupervisor) { |
---|
368 | throw new PHPExcel_Exception('Can only get pseudo-border for supervisor.'); |
---|
369 | } |
---|
370 | return $this->_horizontal; |
---|
371 | } |
---|
372 | |
---|
373 | /** |
---|
374 | * Get DiagonalDirection |
---|
375 | * |
---|
376 | * @return int |
---|
377 | */ |
---|
378 | public function getDiagonalDirection() { |
---|
379 | if ($this->_isSupervisor) { |
---|
380 | return $this->getSharedComponent()->getDiagonalDirection(); |
---|
381 | } |
---|
382 | return $this->_diagonalDirection; |
---|
383 | } |
---|
384 | |
---|
385 | /** |
---|
386 | * Set DiagonalDirection |
---|
387 | * |
---|
388 | * @param int $pValue |
---|
389 | * @return PHPExcel_Style_Borders |
---|
390 | */ |
---|
391 | public function setDiagonalDirection($pValue = PHPExcel_Style_Borders::DIAGONAL_NONE) { |
---|
392 | if ($pValue == '') { |
---|
393 | $pValue = PHPExcel_Style_Borders::DIAGONAL_NONE; |
---|
394 | } |
---|
395 | if ($this->_isSupervisor) { |
---|
396 | $styleArray = $this->getStyleArray(array('diagonaldirection' => $pValue)); |
---|
397 | $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); |
---|
398 | } else { |
---|
399 | $this->_diagonalDirection = $pValue; |
---|
400 | } |
---|
401 | return $this; |
---|
402 | } |
---|
403 | |
---|
404 | /** |
---|
405 | * Get hash code |
---|
406 | * |
---|
407 | * @return string Hash code |
---|
408 | */ |
---|
409 | public function getHashCode() { |
---|
410 | if ($this->_isSupervisor) { |
---|
411 | return $this->getSharedComponent()->getHashcode(); |
---|
412 | } |
---|
413 | return md5( |
---|
414 | $this->getLeft()->getHashCode() |
---|
415 | . $this->getRight()->getHashCode() |
---|
416 | . $this->getTop()->getHashCode() |
---|
417 | . $this->getBottom()->getHashCode() |
---|
418 | . $this->getDiagonal()->getHashCode() |
---|
419 | . $this->getDiagonalDirection() |
---|
420 | . __CLASS__ |
---|
421 | ); |
---|
422 | } |
---|
423 | |
---|
424 | } |
---|