[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * PHPExcel_Style_Border 5 * 6 * Copyright (c) 2006 - 2015 PHPExcel 7 * 8 * This library is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU Lesser General Public 10 * License as published by the Free Software Foundation; either 11 * version 2.1 of the License, or (at your option) any later version. 12 * 13 * This library is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 * Lesser General Public License for more details. 17 * 18 * You should have received a copy of the GNU Lesser General Public 19 * License along with this library; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 21 * 22 * @category PHPExcel 23 * @package PHPExcel_Style 24 * @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel) 25 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL 26 * @version ##VERSION##, ##DATE## 27 */ 28 class PHPExcel_Style_Border extends PHPExcel_Style_Supervisor implements PHPExcel_IComparable 29 { 30 /* Border style */ 31 const BORDER_NONE = 'none'; 32 const BORDER_DASHDOT = 'dashDot'; 33 const BORDER_DASHDOTDOT = 'dashDotDot'; 34 const BORDER_DASHED = 'dashed'; 35 const BORDER_DOTTED = 'dotted'; 36 const BORDER_DOUBLE = 'double'; 37 const BORDER_HAIR = 'hair'; 38 const BORDER_MEDIUM = 'medium'; 39 const BORDER_MEDIUMDASHDOT = 'mediumDashDot'; 40 const BORDER_MEDIUMDASHDOTDOT = 'mediumDashDotDot'; 41 const BORDER_MEDIUMDASHED = 'mediumDashed'; 42 const BORDER_SLANTDASHDOT = 'slantDashDot'; 43 const BORDER_THICK = 'thick'; 44 const BORDER_THIN = 'thin'; 45 46 /** 47 * Border style 48 * 49 * @var string 50 */ 51 protected $borderStyle = PHPExcel_Style_Border::BORDER_NONE; 52 53 /** 54 * Border color 55 * 56 * @var PHPExcel_Style_Color 57 */ 58 protected $color; 59 60 /** 61 * Parent property name 62 * 63 * @var string 64 */ 65 protected $parentPropertyName; 66 67 /** 68 * Create a new PHPExcel_Style_Border 69 * 70 * @param boolean $isSupervisor Flag indicating if this is a supervisor or not 71 * Leave this value at default unless you understand exactly what 72 * its ramifications are 73 * @param boolean $isConditional Flag indicating if this is a conditional style or not 74 * Leave this value at default unless you understand exactly what 75 * its ramifications are 76 */ 77 public function __construct($isSupervisor = false, $isConditional = false) 78 { 79 // Supervisor? 80 parent::__construct($isSupervisor); 81 82 // Initialise values 83 $this->color = new PHPExcel_Style_Color(PHPExcel_Style_Color::COLOR_BLACK, $isSupervisor); 84 85 // bind parent if we are a supervisor 86 if ($isSupervisor) { 87 $this->color->bindParent($this, 'color'); 88 } 89 } 90 91 /** 92 * Bind parent. Only used for supervisor 93 * 94 * @param PHPExcel_Style_Borders $parent 95 * @param string $parentPropertyName 96 * @return PHPExcel_Style_Border 97 */ 98 public function bindParent($parent, $parentPropertyName = null) 99 { 100 $this->parent = $parent; 101 $this->parentPropertyName = $parentPropertyName; 102 return $this; 103 } 104 105 /** 106 * Get the shared style component for the currently active cell in currently active sheet. 107 * Only used for style supervisor 108 * 109 * @return PHPExcel_Style_Border 110 * @throws PHPExcel_Exception 111 */ 112 public function getSharedComponent() 113 { 114 switch ($this->parentPropertyName) { 115 case 'allBorders': 116 case 'horizontal': 117 case 'inside': 118 case 'outline': 119 case 'vertical': 120 throw new PHPExcel_Exception('Cannot get shared component for a pseudo-border.'); 121 break; 122 case 'bottom': 123 return $this->parent->getSharedComponent()->getBottom(); 124 case 'diagonal': 125 return $this->parent->getSharedComponent()->getDiagonal(); 126 case 'left': 127 return $this->parent->getSharedComponent()->getLeft(); 128 case 'right': 129 return $this->parent->getSharedComponent()->getRight(); 130 case 'top': 131 return $this->parent->getSharedComponent()->getTop(); 132 } 133 } 134 135 /** 136 * Build style array from subcomponents 137 * 138 * @param array $array 139 * @return array 140 */ 141 public function getStyleArray($array) 142 { 143 switch ($this->parentPropertyName) { 144 case 'allBorders': 145 case 'bottom': 146 case 'diagonal': 147 case 'horizontal': 148 case 'inside': 149 case 'left': 150 case 'outline': 151 case 'right': 152 case 'top': 153 case 'vertical': 154 $key = strtolower('vertical'); 155 break; 156 } 157 return $this->parent->getStyleArray(array($key => $array)); 158 } 159 160 /** 161 * Apply styles from array 162 * 163 * <code> 164 * $objPHPExcel->getActiveSheet()->getStyle('B2')->getBorders()->getTop()->applyFromArray( 165 * array( 166 * 'style' => PHPExcel_Style_Border::BORDER_DASHDOT, 167 * 'color' => array( 168 * 'rgb' => '808080' 169 * ) 170 * ) 171 * ); 172 * </code> 173 * 174 * @param array $pStyles Array containing style information 175 * @throws PHPExcel_Exception 176 * @return PHPExcel_Style_Border 177 */ 178 public function applyFromArray($pStyles = null) 179 { 180 if (is_array($pStyles)) { 181 if ($this->isSupervisor) { 182 $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($this->getStyleArray($pStyles)); 183 } else { 184 if (isset($pStyles['style'])) { 185 $this->setBorderStyle($pStyles['style']); 186 } 187 if (isset($pStyles['color'])) { 188 $this->getColor()->applyFromArray($pStyles['color']); 189 } 190 } 191 } else { 192 throw new PHPExcel_Exception("Invalid style array passed."); 193 } 194 return $this; 195 } 196 197 /** 198 * Get Border style 199 * 200 * @return string 201 */ 202 public function getBorderStyle() 203 { 204 if ($this->isSupervisor) { 205 return $this->getSharedComponent()->getBorderStyle(); 206 } 207 return $this->borderStyle; 208 } 209 210 /** 211 * Set Border style 212 * 213 * @param string|boolean $pValue 214 * When passing a boolean, FALSE equates PHPExcel_Style_Border::BORDER_NONE 215 * and TRUE to PHPExcel_Style_Border::BORDER_MEDIUM 216 * @return PHPExcel_Style_Border 217 */ 218 public function setBorderStyle($pValue = PHPExcel_Style_Border::BORDER_NONE) 219 { 220 221 if (empty($pValue)) { 222 $pValue = PHPExcel_Style_Border::BORDER_NONE; 223 } elseif (is_bool($pValue) && $pValue) { 224 $pValue = PHPExcel_Style_Border::BORDER_MEDIUM; 225 } 226 if ($this->isSupervisor) { 227 $styleArray = $this->getStyleArray(array('style' => $pValue)); 228 $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); 229 } else { 230 $this->borderStyle = $pValue; 231 } 232 return $this; 233 } 234 235 /** 236 * Get Border Color 237 * 238 * @return PHPExcel_Style_Color 239 */ 240 public function getColor() 241 { 242 return $this->color; 243 } 244 245 /** 246 * Set Border Color 247 * 248 * @param PHPExcel_Style_Color $pValue 249 * @throws PHPExcel_Exception 250 * @return PHPExcel_Style_Border 251 */ 252 public function setColor(PHPExcel_Style_Color $pValue = null) 253 { 254 // make sure parameter is a real color and not a supervisor 255 $color = $pValue->getIsSupervisor() ? $pValue->getSharedComponent() : $pValue; 256 257 if ($this->isSupervisor) { 258 $styleArray = $this->getColor()->getStyleArray(array('argb' => $color->getARGB())); 259 $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); 260 } else { 261 $this->color = $color; 262 } 263 return $this; 264 } 265 266 /** 267 * Get hash code 268 * 269 * @return string Hash code 270 */ 271 public function getHashCode() 272 { 273 if ($this->isSupervisor) { 274 return $this->getSharedComponent()->getHashCode(); 275 } 276 return md5( 277 $this->borderStyle . 278 $this->color->getHashCode() . 279 __CLASS__ 280 ); 281 } 282 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |