[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * PHPExcel_NamedRange 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 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_NamedRange 29 { 30 /** 31 * Range name 32 * 33 * @var string 34 */ 35 private $name; 36 37 /** 38 * Worksheet on which the named range can be resolved 39 * 40 * @var PHPExcel_Worksheet 41 */ 42 private $worksheet; 43 44 /** 45 * Range of the referenced cells 46 * 47 * @var string 48 */ 49 private $range; 50 51 /** 52 * Is the named range local? (i.e. can only be used on $this->worksheet) 53 * 54 * @var bool 55 */ 56 private $localOnly; 57 58 /** 59 * Scope 60 * 61 * @var PHPExcel_Worksheet 62 */ 63 private $scope; 64 65 /** 66 * Create a new NamedRange 67 * 68 * @param string $pName 69 * @param PHPExcel_Worksheet $pWorksheet 70 * @param string $pRange 71 * @param bool $pLocalOnly 72 * @param PHPExcel_Worksheet|null $pScope Scope. Only applies when $pLocalOnly = true. Null for global scope. 73 * @throws PHPExcel_Exception 74 */ 75 public function __construct($pName = null, PHPExcel_Worksheet $pWorksheet, $pRange = 'A1', $pLocalOnly = false, $pScope = null) 76 { 77 // Validate data 78 if (($pName === null) || ($pWorksheet === null) || ($pRange === null)) { 79 throw new PHPExcel_Exception('Parameters can not be null.'); 80 } 81 82 // Set local members 83 $this->name = $pName; 84 $this->worksheet = $pWorksheet; 85 $this->range = $pRange; 86 $this->localOnly = $pLocalOnly; 87 $this->scope = ($pLocalOnly == true) ? (($pScope == null) ? $pWorksheet : $pScope) : null; 88 } 89 90 /** 91 * Get name 92 * 93 * @return string 94 */ 95 public function getName() 96 { 97 return $this->name; 98 } 99 100 /** 101 * Set name 102 * 103 * @param string $value 104 * @return PHPExcel_NamedRange 105 */ 106 public function setName($value = null) 107 { 108 if ($value !== null) { 109 // Old title 110 $oldTitle = $this->name; 111 112 // Re-attach 113 if ($this->worksheet !== null) { 114 $this->worksheet->getParent()->removeNamedRange($this->name, $this->worksheet); 115 } 116 $this->name = $value; 117 118 if ($this->worksheet !== null) { 119 $this->worksheet->getParent()->addNamedRange($this); 120 } 121 122 // New title 123 $newTitle = $this->name; 124 PHPExcel_ReferenceHelper::getInstance()->updateNamedFormulas($this->worksheet->getParent(), $oldTitle, $newTitle); 125 } 126 return $this; 127 } 128 129 /** 130 * Get worksheet 131 * 132 * @return PHPExcel_Worksheet 133 */ 134 public function getWorksheet() 135 { 136 return $this->worksheet; 137 } 138 139 /** 140 * Set worksheet 141 * 142 * @param PHPExcel_Worksheet $value 143 * @return PHPExcel_NamedRange 144 */ 145 public function setWorksheet(PHPExcel_Worksheet $value = null) 146 { 147 if ($value !== null) { 148 $this->worksheet = $value; 149 } 150 return $this; 151 } 152 153 /** 154 * Get range 155 * 156 * @return string 157 */ 158 public function getRange() 159 { 160 return $this->range; 161 } 162 163 /** 164 * Set range 165 * 166 * @param string $value 167 * @return PHPExcel_NamedRange 168 */ 169 public function setRange($value = null) 170 { 171 if ($value !== null) { 172 $this->range = $value; 173 } 174 return $this; 175 } 176 177 /** 178 * Get localOnly 179 * 180 * @return bool 181 */ 182 public function getLocalOnly() 183 { 184 return $this->localOnly; 185 } 186 187 /** 188 * Set localOnly 189 * 190 * @param bool $value 191 * @return PHPExcel_NamedRange 192 */ 193 public function setLocalOnly($value = false) 194 { 195 $this->localOnly = $value; 196 $this->scope = $value ? $this->worksheet : null; 197 return $this; 198 } 199 200 /** 201 * Get scope 202 * 203 * @return PHPExcel_Worksheet|null 204 */ 205 public function getScope() 206 { 207 return $this->scope; 208 } 209 210 /** 211 * Set scope 212 * 213 * @param PHPExcel_Worksheet|null $value 214 * @return PHPExcel_NamedRange 215 */ 216 public function setScope(PHPExcel_Worksheet $value = null) 217 { 218 $this->scope = $value; 219 $this->localOnly = ($value == null) ? false : true; 220 return $this; 221 } 222 223 /** 224 * Resolve a named range to a regular cell range 225 * 226 * @param string $pNamedRange Named range 227 * @param PHPExcel_Worksheet|null $pSheet Scope. Use null for global scope 228 * @return PHPExcel_NamedRange 229 */ 230 public static function resolveRange($pNamedRange = '', PHPExcel_Worksheet $pSheet) 231 { 232 return $pSheet->getParent()->getNamedRange($pNamedRange, $pSheet); 233 } 234 235 /** 236 * Implement PHP __clone to create a deep clone, not just a shallow copy. 237 */ 238 public function __clone() 239 { 240 $vars = get_object_vars($this); 241 foreach ($vars as $key => $value) { 242 if (is_object($value)) { 243 $this->$key = clone $value; 244 } else { 245 $this->$key = $value; 246 } 247 } 248 } 249 }
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 |