File Source for NamedRange.php

PHPExcel

# Source for file NamedRange.php

Documentation is available at NamedRange.php

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

Documentation generated on Sun, 27 Feb 2011 16:32:49 -0800 by phpDocumentor 1.4.3