6 * Copyright (c) 2006 - 2015 PHPExcel
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.
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.
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
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##
28 class PHPExcel_NamedRange
38 * Worksheet on which the named range can be resolved
40 * @var PHPExcel_Worksheet
45 * Range of the referenced cells
52 * Is the named range local? (i.e. can only be used on $this->worksheet)
61 * @var PHPExcel_Worksheet
66 * Create a new NamedRange
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
75 public function __construct($pName = null, PHPExcel_Worksheet
$pWorksheet, $pRange = 'A1', $pLocalOnly = false, $pScope = null)
78 if (($pName === null) ||
($pWorksheet === null) ||
($pRange === null)) {
79 throw new PHPExcel_Exception('Parameters can not be null.');
84 $this->worksheet
= $pWorksheet;
85 $this->range
= $pRange;
86 $this->localOnly
= $pLocalOnly;
87 $this->scope
= ($pLocalOnly == true) ?
(($pScope == null) ?
$pWorksheet : $pScope) : null;
95 public function getName()
103 * @param string $value
104 * @return PHPExcel_NamedRange
106 public function setName($value = null)
108 if ($value !== null) {
110 $oldTitle = $this->name
;
113 if ($this->worksheet
!== null) {
114 $this->worksheet
->getParent()->removeNamedRange($this->name
, $this->worksheet
);
116 $this->name
= $value;
118 if ($this->worksheet
!== null) {
119 $this->worksheet
->getParent()->addNamedRange($this);
123 $newTitle = $this->name
;
124 PHPExcel_ReferenceHelper
::getInstance()->updateNamedFormulas($this->worksheet
->getParent(), $oldTitle, $newTitle);
132 * @return PHPExcel_Worksheet
134 public function getWorksheet()
136 return $this->worksheet
;
142 * @param PHPExcel_Worksheet $value
143 * @return PHPExcel_NamedRange
145 public function setWorksheet(PHPExcel_Worksheet
$value = null)
147 if ($value !== null) {
148 $this->worksheet
= $value;
158 public function getRange()
166 * @param string $value
167 * @return PHPExcel_NamedRange
169 public function setRange($value = null)
171 if ($value !== null) {
172 $this->range
= $value;
182 public function getLocalOnly()
184 return $this->localOnly
;
191 * @return PHPExcel_NamedRange
193 public function setLocalOnly($value = false)
195 $this->localOnly
= $value;
196 $this->scope
= $value ?
$this->worksheet
: null;
203 * @return PHPExcel_Worksheet|null
205 public function getScope()
213 * @param PHPExcel_Worksheet|null $value
214 * @return PHPExcel_NamedRange
216 public function setScope(PHPExcel_Worksheet
$value = null)
218 $this->scope
= $value;
219 $this->localOnly
= ($value == null) ?
false : true;
224 * Resolve a named range to a regular cell range
226 * @param string $pNamedRange Named range
227 * @param PHPExcel_Worksheet|null $pSheet Scope. Use null for global scope
228 * @return PHPExcel_NamedRange
230 public static function resolveRange($pNamedRange = '', PHPExcel_Worksheet
$pSheet)
232 return $pSheet->getParent()->getNamedRange($pNamedRange, $pSheet);
236 * Implement PHP __clone to create a deep clone, not just a shallow copy.
238 public function __clone()
240 $vars = get_object_vars($this);
241 foreach ($vars as $key => $value) {
242 if (is_object($value)) {
243 $this->$key = clone $value;
245 $this->$key = $value;