PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.0.10
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.0.10
4.0.8 4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.2 3.1.3 3.10.0 3.10.1 3.10.10 3.10.11 3.10.12 3.10.13 3.10.14 3.10.15 3.10.2 3.10.3 All 149 releases
← All changes | vendor/phpoffice/phpexcel/Classes/PHPExcel/Cell.php +867 -877 3.1.13.0.10 View file →
@@ -1,369 +1,371 @@
1 1 <?php
2 -
3 2 /**
4 - * PHPExcel_Cell
3 + * PHPExcel
5 4 *
6 - * Copyright (c) 2006 - 2015 PHPExcel
5 + * Copyright (c) 2006 - 2014 PHPExcel
7 6 *
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.
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.
12 11 *
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.
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.
17 16 *
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
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
21 20 *
22 - * @category PHPExcel
23 - * @package PHPExcel_Cell
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##
21 + * @category PHPExcel
22 + * @package PHPExcel_Cell
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 ##VERSION##, ##DATE##
27 26 */
27 +
28 +
29 +/**
30 + * PHPExcel_Cell
31 + *
32 + * @category PHPExcel
33 + * @package PHPExcel_Cell
34 + * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
35 + */
28 36 class PHPExcel_Cell
29 37 {
30 - /**
31 - * Default range variable constant
32 - *
33 - * @var string
34 - */
35 - const DEFAULT_RANGE = 'A1:A1';
36 38
37 - /**
38 - * Value binder to use
39 - *
40 - * @var PHPExcel_Cell_IValueBinder
41 - */
42 - private static $valueBinder;
39 + /**
40 + * Default range variable constant
41 + *
42 + * @var string
43 + */
44 + const DEFAULT_RANGE = 'A1:A1';
43 45
44 - /**
45 - * Value of the cell
46 - *
47 - * @var mixed
48 - */
49 - private $value;
46 + /**
47 + * Value binder to use
48 + *
49 + * @var PHPExcel_Cell_IValueBinder
50 + */
51 + private static $_valueBinder = NULL;
50 52
51 - /**
52 - * Calculated value of the cell (used for caching)
53 - * This returns the value last calculated by MS Excel or whichever spreadsheet program was used to
54 - * create the original spreadsheet file.
55 - * Note that this value is not guaranteed to reflect the actual calculated value because it is
56 - * possible that auto-calculation was disabled in the original spreadsheet, and underlying data
57 - * values used by the formula have changed since it was last calculated.
58 - *
59 - * @var mixed
60 - */
61 - private $calculatedValue;
53 + /**
54 + * Value of the cell
55 + *
56 + * @var mixed
57 + */
58 + private $_value;
62 59
63 - /**
64 - * Type of the cell data
65 - *
66 - * @var string
67 - */
68 - private $dataType;
60 + /**
61 + * Calculated value of the cell (used for caching)
62 + * This returns the value last calculated by MS Excel or whichever spreadsheet program was used to
63 + * create the original spreadsheet file.
64 + * Note that this value is not guaranteed to reflect the actual calculated value because it is
65 + * possible that auto-calculation was disabled in the original spreadsheet, and underlying data
66 + * values used by the formula have changed since it was last calculated.
67 + *
68 + * @var mixed
69 + */
70 + private $_calculatedValue = NULL;
69 71
70 - /**
71 - * Parent worksheet
72 - *
73 - * @var PHPExcel_CachedObjectStorage_CacheBase
74 - */
75 - private $parent;
72 + /**
73 + * Type of the cell data
74 + *
75 + * @var string
76 + */
77 + private $_dataType;
76 78
77 - /**
78 - * Index to cellXf
79 - *
80 - * @var int
81 - */
82 - private $xfIndex = 0;
79 + /**
80 + * Parent worksheet
81 + *
82 + * @var PHPExcel_CachedObjectStorage_CacheBase
83 + */
84 + private $_parent;
83 85
84 - /**
85 - * Attributes of the formula
86 - *
87 - */
88 - private $formulaAttributes;
86 + /**
87 + * Index to cellXf
88 + *
89 + * @var int
90 + */
91 + private $_xfIndex = 0;
89 92
93 + /**
94 + * Attributes of the formula
95 + *
96 + */
97 + private $_formulaAttributes;
90 98
91 - /**
92 - * Send notification to the cache controller
93 - *
94 - * @return void
95 - **/
96 - public function notifyCacheController()
97 - {
98 - $this->parent->updateCacheData($this);
99 99
100 - return $this;
101 - }
100 + /**
101 + * Send notification to the cache controller
102 + *
103 + * @return void
104 + **/
105 + public function notifyCacheController() {
106 + $this->_parent->updateCacheData($this);
102 107
103 - public function detach()
104 - {
105 - $this->parent = null;
106 - }
108 + return $this;
109 + }
107 110
108 - public function attach(PHPExcel_CachedObjectStorage_CacheBase $parent)
109 - {
110 - $this->parent = $parent;
111 - }
111 + public function detach() {
112 + $this->_parent = NULL;
113 + }
112 114
115 + public function attach(PHPExcel_CachedObjectStorage_CacheBase $parent) {
116 + $this->_parent = $parent;
117 + }
113 118
114 - /**
115 - * Create a new Cell
116 - *
117 - * @param mixed $pValue
118 - * @param string $pDataType
119 - * @param PHPExcel_Worksheet $pSheet
120 - * @throws PHPExcel_Exception
121 - */
122 - public function __construct($pValue = null, $pDataType = null, PHPExcel_Worksheet $pSheet = null)
123 - {
124 - // Initialise cell value
125 - $this->value = $pValue;
126 119
127 - // Set worksheet cache
128 - $this->parent = $pSheet->getCellCacheController();
120 + /**
121 + * Create a new Cell
122 + *
123 + * @param mixed $pValue
124 + * @param string $pDataType
125 + * @param PHPExcel_Worksheet $pSheet
126 + * @throws PHPExcel_Exception
127 + */
128 + public function __construct($pValue = NULL, $pDataType = NULL, PHPExcel_Worksheet $pSheet = NULL)
129 + {
130 + // Initialise cell value
131 + $this->_value = $pValue;
129 132
130 - // Set datatype?
131 - if ($pDataType !== null) {
132 - if ($pDataType == PHPExcel_Cell_DataType::TYPE_STRING2) {
133 - $pDataType = PHPExcel_Cell_DataType::TYPE_STRING;
134 - }
135 - $this->dataType = $pDataType;
136 - } elseif (!self::getValueBinder()->bindValue($this, $pValue)) {
133 + // Set worksheet cache
134 + $this->_parent = $pSheet->getCellCacheController();
135 +
136 + // Set datatype?
137 + if ($pDataType !== NULL) {
138 + if ($pDataType == PHPExcel_Cell_DataType::TYPE_STRING2)
139 + $pDataType = PHPExcel_Cell_DataType::TYPE_STRING;
140 + $this->_dataType = $pDataType;
141 + } elseif (!self::getValueBinder()->bindValue($this, $pValue)) {
137 142 throw new PHPExcel_Exception("Value could not be bound to cell.");
138 - }
139 - }
143 + }
144 + }
140 145
141 - /**
142 - * Get cell coordinate column
143 - *
144 - * @return string
145 - */
146 - public function getColumn()
147 - {
148 - return $this->parent->getCurrentColumn();
149 - }
146 + /**
147 + * Get cell coordinate column
148 + *
149 + * @return string
150 + */
151 + public function getColumn()
152 + {
153 + return $this->_parent->getCurrentColumn();
154 + }
150 155
151 - /**
152 - * Get cell coordinate row
153 - *
154 - * @return int
155 - */
156 - public function getRow()
157 - {
158 - return $this->parent->getCurrentRow();
159 - }
156 + /**
157 + * Get cell coordinate row
158 + *
159 + * @return int
160 + */
161 + public function getRow()
162 + {
163 + return $this->_parent->getCurrentRow();
164 + }
160 165
161 - /**
162 - * Get cell coordinate
163 - *
164 - * @return string
165 - */
166 - public function getCoordinate()
167 - {
168 - return $this->parent->getCurrentAddress();
169 - }
166 + /**
167 + * Get cell coordinate
168 + *
169 + * @return string
170 + */
171 + public function getCoordinate()
172 + {
173 + return $this->_parent->getCurrentAddress();
174 + }
170 175
171 - /**
172 - * Get cell value
173 - *
174 - * @return mixed
175 - */
176 - public function getValue()
177 - {
178 - return $this->value;
179 - }
176 + /**
177 + * Get cell value
178 + *
179 + * @return mixed
180 + */
181 + public function getValue()
182 + {
183 + return $this->_value;
184 + }
180 185
181 - /**
182 - * Get cell value with formatting
183 - *
184 - * @return string
185 - */
186 - public function getFormattedValue()
187 - {
188 - return (string) PHPExcel_Style_NumberFormat::toFormattedString(
189 - $this->getCalculatedValue(),
190 - $this->getStyle()
191 - ->getNumberFormat()->getFormatCode()
192 - );
193 - }
186 + /**
187 + * Get cell value with formatting
188 + *
189 + * @return string
190 + */
191 + public function getFormattedValue()
192 + {
193 + return (string) PHPExcel_Style_NumberFormat::toFormattedString(
194 + $this->getCalculatedValue(),
195 + $this->getStyle()
196 + ->getNumberFormat()->getFormatCode()
197 + );
198 + }
194 199
195 - /**
196 - * Set cell value
197 - *
198 - * Sets the value for a cell, automatically determining the datatype using the value binder
199 - *
200 - * @param mixed $pValue Value
201 - * @return PHPExcel_Cell
202 - * @throws PHPExcel_Exception
203 - */
204 - public function setValue($pValue = null)
205 - {
206 - if (!self::getValueBinder()->bindValue($this, $pValue)) {
207 - throw new PHPExcel_Exception("Value could not be bound to cell.");
208 - }
209 - return $this;
210 - }
200 + /**
201 + * Set cell value
202 + *
203 + * Sets the value for a cell, automatically determining the datatype using the value binder
204 + *
205 + * @param mixed $pValue Value
206 + * @return PHPExcel_Cell
207 + * @throws PHPExcel_Exception
208 + */
209 + public function setValue($pValue = NULL)
210 + {
211 + if (!self::getValueBinder()->bindValue($this, $pValue)) {
212 + throw new PHPExcel_Exception("Value could not be bound to cell.");
213 + }
214 + return $this;
215 + }
211 216
212 - /**
213 - * Set the value for a cell, with the explicit data type passed to the method (bypassing any use of the value binder)
214 - *
215 - * @param mixed $pValue Value
216 - * @param string $pDataType Explicit data type
217 - * @return PHPExcel_Cell
218 - * @throws PHPExcel_Exception
219 - */
220 - public function setValueExplicit($pValue = null, $pDataType = PHPExcel_Cell_DataType::TYPE_STRING)
221 - {
222 - // set the value according to data type
223 - switch ($pDataType) {
224 - case PHPExcel_Cell_DataType::TYPE_NULL:
225 - $this->value = $pValue;
226 - break;
227 - case PHPExcel_Cell_DataType::TYPE_STRING2:
228 - $pDataType = PHPExcel_Cell_DataType::TYPE_STRING;
229 - // no break
230 - case PHPExcel_Cell_DataType::TYPE_STRING:
231 - // Synonym for string
232 - case PHPExcel_Cell_DataType::TYPE_INLINE:
233 - // Rich text
234 - $this->value = PHPExcel_Cell_DataType::checkString($pValue);
235 - break;
236 - case PHPExcel_Cell_DataType::TYPE_NUMERIC:
237 - $this->value = (float) $pValue;
238 - break;
239 - case PHPExcel_Cell_DataType::TYPE_FORMULA:
240 - $this->value = (string) $pValue;
241 - break;
242 - case PHPExcel_Cell_DataType::TYPE_BOOL:
243 - $this->value = (bool) $pValue;
244 - break;
245 - case PHPExcel_Cell_DataType::TYPE_ERROR:
246 - $this->value = PHPExcel_Cell_DataType::checkErrorCode($pValue);
247 - break;
248 - default:
249 - throw new PHPExcel_Exception('Invalid datatype: ' . $pDataType);
250 - break;
251 - }
217 + /**
218 + * Set the value for a cell, with the explicit data type passed to the method (bypassing any use of the value binder)
219 + *
220 + * @param mixed $pValue Value
221 + * @param string $pDataType Explicit data type
222 + * @return PHPExcel_Cell
223 + * @throws PHPExcel_Exception
224 + */
225 + public function setValueExplicit($pValue = NULL, $pDataType = PHPExcel_Cell_DataType::TYPE_STRING)
226 + {
227 + // set the value according to data type
228 + switch ($pDataType) {
229 + case PHPExcel_Cell_DataType::TYPE_NULL:
230 + $this->_value = $pValue;
231 + break;
232 + case PHPExcel_Cell_DataType::TYPE_STRING2:
233 + $pDataType = PHPExcel_Cell_DataType::TYPE_STRING;
234 + case PHPExcel_Cell_DataType::TYPE_STRING:
235 + case PHPExcel_Cell_DataType::TYPE_INLINE:
236 + $this->_value = PHPExcel_Cell_DataType::checkString($pValue);
237 + break;
238 + case PHPExcel_Cell_DataType::TYPE_NUMERIC:
239 + $this->_value = (float)$pValue;
240 + break;
241 + case PHPExcel_Cell_DataType::TYPE_FORMULA:
242 + $this->_value = (string)$pValue;
243 + break;
244 + case PHPExcel_Cell_DataType::TYPE_BOOL:
245 + $this->_value = (bool)$pValue;
246 + break;
247 + case PHPExcel_Cell_DataType::TYPE_ERROR:
248 + $this->_value = PHPExcel_Cell_DataType::checkErrorCode($pValue);
249 + break;
250 + default:
251 + throw new PHPExcel_Exception('Invalid datatype: ' . $pDataType);
252 + break;
253 + }
252 254
253 - // set the datatype
254 - $this->dataType = $pDataType;
255 + // set the datatype
256 + $this->_dataType = $pDataType;
255 257
256 - return $this->notifyCacheController();
257 - }
258 + return $this->notifyCacheController();
259 + }
258 260
259 - /**
260 - * Get calculated cell value
261 - *
262 - * @deprecated Since version 1.7.8 for planned changes to cell for array formula handling
263 - *
264 - * @param boolean $resetLog Whether the calculation engine logger should be reset or not
265 - * @return mixed
266 - * @throws PHPExcel_Exception
267 - */
268 - public function getCalculatedValue($resetLog = true)
269 - {
270 -//echo 'Cell '.$this->getCoordinate().' value is a '.$this->dataType.' with a value of '.$this->getValue().PHP_EOL;
271 - if ($this->dataType == PHPExcel_Cell_DataType::TYPE_FORMULA) {
272 - try {
261 + /**
262 + * Get calculated cell value
263 + *
264 + * @deprecated Since version 1.7.8 for planned changes to cell for array formula handling
265 + *
266 + * @param boolean $resetLog Whether the calculation engine logger should be reset or not
267 + * @return mixed
268 + * @throws PHPExcel_Exception
269 + */
270 + public function getCalculatedValue($resetLog = TRUE)
271 + {
272 +//echo 'Cell '.$this->getCoordinate().' value is a '.$this->_dataType.' with a value of '.$this->getValue().PHP_EOL;
273 + if ($this->_dataType == PHPExcel_Cell_DataType::TYPE_FORMULA) {
274 + try {
273 275 //echo 'Cell value for '.$this->getCoordinate().' is a formula: Calculating value'.PHP_EOL;
274 - $result = PHPExcel_Calculation::getInstance(
275 - $this->getWorksheet()->getParent()
276 - )->calculateCellValue($this, $resetLog);
276 + $result = PHPExcel_Calculation::getInstance(
277 + $this->getWorksheet()->getParent()
278 + )->calculateCellValue($this,$resetLog);
277 279 //echo $this->getCoordinate().' calculation result is '.$result.PHP_EOL;
278 - // We don't yet handle array returns
279 - if (is_array($result)) {
280 - while (is_array($result)) {
281 - $result = array_pop($result);
282 - }
283 - }
284 - } catch (PHPExcel_Exception $ex) {
285 - if (($ex->getMessage() === 'Unable to access External Workbook') && ($this->calculatedValue !== null)) {
286 -//echo 'Returning fallback value of '.$this->calculatedValue.' for cell '.$this->getCoordinate().PHP_EOL;
287 - return $this->calculatedValue; // Fallback for calculations referencing external files.
288 - }
280 + // We don't yet handle array returns
281 + if (is_array($result)) {
282 + while (is_array($result)) {
283 + $result = array_pop($result);
284 + }
285 + }
286 + } catch ( PHPExcel_Exception $ex ) {
287 + if (($ex->getMessage() === 'Unable to access External Workbook') && ($this->_calculatedValue !== NULL)) {
288 +//echo 'Returning fallback value of '.$this->_calculatedValue.' for cell '.$this->getCoordinate().PHP_EOL;
289 + return $this->_calculatedValue; // Fallback for calculations referencing external files.
290 + }
289 291 //echo 'Calculation Exception: '.$ex->getMessage().PHP_EOL;
290 - $result = '#N/A';
291 - throw new PHPExcel_Calculation_Exception(
292 - $this->getWorksheet()->getTitle().'!'.$this->getCoordinate().' -> '.$ex->getMessage()
293 - );
294 - }
292 + $result = '#N/A';
293 + throw new PHPExcel_Calculation_Exception(
294 + $this->getWorksheet()->getTitle().'!'.$this->getCoordinate().' -> '.$ex->getMessage()
295 + );
296 + }
295 297
296 - if ($result === '#Not Yet Implemented') {
297 -//echo 'Returning fallback value of '.$this->calculatedValue.' for cell '.$this->getCoordinate().PHP_EOL;
298 - return $this->calculatedValue; // Fallback if calculation engine does not support the formula.
299 - }
298 + if ($result === '#Not Yet Implemented') {
299 +//echo 'Returning fallback value of '.$this->_calculatedValue.' for cell '.$this->getCoordinate().PHP_EOL;
300 + return $this->_calculatedValue; // Fallback if calculation engine does not support the formula.
301 + }
300 302 //echo 'Returning calculated value of '.$result.' for cell '.$this->getCoordinate().PHP_EOL;
301 - return $result;
302 - } elseif ($this->value instanceof PHPExcel_RichText) {
303 -// echo 'Cell value for '.$this->getCoordinate().' is rich text: Returning data value of '.$this->value.'<br />';
304 - return $this->value->getPlainText();
305 - }
306 -// echo 'Cell value for '.$this->getCoordinate().' is not a formula: Returning data value of '.$this->value.'<br />';
307 - return $this->value;
308 - }
303 + return $result;
304 + } elseif($this->_value instanceof PHPExcel_RichText) {
305 +// echo 'Cell value for '.$this->getCoordinate().' is rich text: Returning data value of '.$this->_value.'<br />';
306 + return $this->_value->getPlainText();
307 + }
308 +// echo 'Cell value for '.$this->getCoordinate().' is not a formula: Returning data value of '.$this->_value.'<br />';
309 + return $this->_value;
310 + }
309 311
310 - /**
311 - * Set old calculated value (cached)
312 - *
313 - * @param mixed $pValue Value
314 - * @return PHPExcel_Cell
315 - */
316 - public function setCalculatedValue($pValue = null)
317 - {
318 - if ($pValue !== null) {
319 - $this->calculatedValue = (is_numeric($pValue)) ? (float) $pValue : $pValue;
320 - }
312 + /**
313 + * Set old calculated value (cached)
314 + *
315 + * @param mixed $pValue Value
316 + * @return PHPExcel_Cell
317 + */
318 + public function setCalculatedValue($pValue = NULL)
319 + {
320 + if ($pValue !== NULL) {
321 + $this->_calculatedValue = (is_numeric($pValue)) ? (float) $pValue : $pValue;
322 + }
321 323
322 - return $this->notifyCacheController();
323 - }
324 + return $this->notifyCacheController();
325 + }
324 326
325 - /**
326 - * Get old calculated value (cached)
327 - * This returns the value last calculated by MS Excel or whichever spreadsheet program was used to
328 - * create the original spreadsheet file.
329 - * Note that this value is not guaranteed to refelect the actual calculated value because it is
330 - * possible that auto-calculation was disabled in the original spreadsheet, and underlying data
331 - * values used by the formula have changed since it was last calculated.
332 - *
333 - * @return mixed
334 - */
335 - public function getOldCalculatedValue()
336 - {
337 - return $this->calculatedValue;
338 - }
327 + /**
328 + * Get old calculated value (cached)
329 + * This returns the value last calculated by MS Excel or whichever spreadsheet program was used to
330 + * create the original spreadsheet file.
331 + * Note that this value is not guaranteed to refelect the actual calculated value because it is
332 + * possible that auto-calculation was disabled in the original spreadsheet, and underlying data
333 + * values used by the formula have changed since it was last calculated.
334 + *
335 + * @return mixed
336 + */
337 + public function getOldCalculatedValue()
338 + {
339 + return $this->_calculatedValue;
340 + }
339 341
340 - /**
341 - * Get cell data type
342 - *
343 - * @return string
344 - */
345 - public function getDataType()
346 - {
347 - return $this->dataType;
348 - }
342 + /**
343 + * Get cell data type
344 + *
345 + * @return string
346 + */
347 + public function getDataType()
348 + {
349 + return $this->_dataType;
350 + }
349 351
350 - /**
351 - * Set cell data type
352 - *
353 - * @param string $pDataType
354 - * @return PHPExcel_Cell
355 - */
356 - public function setDataType($pDataType = PHPExcel_Cell_DataType::TYPE_STRING)
357 - {
358 - if ($pDataType == PHPExcel_Cell_DataType::TYPE_STRING2) {
359 - $pDataType = PHPExcel_Cell_DataType::TYPE_STRING;
360 - }
361 - $this->dataType = $pDataType;
352 + /**
353 + * Set cell data type
354 + *
355 + * @param string $pDataType
356 + * @return PHPExcel_Cell
357 + */
358 + public function setDataType($pDataType = PHPExcel_Cell_DataType::TYPE_STRING)
359 + {
360 + if ($pDataType == PHPExcel_Cell_DataType::TYPE_STRING2)
361 + $pDataType = PHPExcel_Cell_DataType::TYPE_STRING;
362 362
363 - return $this->notifyCacheController();
364 - }
363 + $this->_dataType = $pDataType;
365 364
365 + return $this->notifyCacheController();
366 + }
367 +
366 368 /**
367 369 * Identify if the cell contains a formula
368 370 *
369 371 * @return boolean
@@ -369,144 +371,140 @@
369 371 * @return boolean
370 372 */
371 373 public function isFormula()
372 374 {
373 - return $this->dataType == PHPExcel_Cell_DataType::TYPE_FORMULA;
375 + return $this->_dataType == PHPExcel_Cell_DataType::TYPE_FORMULA;
374 376 }
375 377
376 - /**
377 - * Does this cell contain Data validation rules?
378 - *
379 - * @return boolean
380 - * @throws PHPExcel_Exception
381 - */
382 - public function hasDataValidation()
383 - {
384 - if (!isset($this->parent)) {
385 - throw new PHPExcel_Exception('Cannot check for data validation when cell is not bound to a worksheet');
386 - }
378 + /**
379 + * Does this cell contain Data validation rules?
380 + *
381 + * @return boolean
382 + * @throws PHPExcel_Exception
383 + */
384 + public function hasDataValidation()
385 + {
386 + if (!isset($this->_parent)) {
387 + throw new PHPExcel_Exception('Cannot check for data validation when cell is not bound to a worksheet');
388 + }
387 389
388 - return $this->getWorksheet()->dataValidationExists($this->getCoordinate());
389 - }
390 + return $this->getWorksheet()->dataValidationExists($this->getCoordinate());
391 + }
390 392
391 - /**
392 - * Get Data validation rules
393 - *
394 - * @return PHPExcel_Cell_DataValidation
395 - * @throws PHPExcel_Exception
396 - */
397 - public function getDataValidation()
398 - {
399 - if (!isset($this->parent)) {
400 - throw new PHPExcel_Exception('Cannot get data validation for cell that is not bound to a worksheet');
401 - }
393 + /**
394 + * Get Data validation rules
395 + *
396 + * @return PHPExcel_Cell_DataValidation
397 + * @throws PHPExcel_Exception
398 + */
399 + public function getDataValidation()
400 + {
401 + if (!isset($this->_parent)) {
402 + throw new PHPExcel_Exception('Cannot get data validation for cell that is not bound to a worksheet');
403 + }
402 404
403 - return $this->getWorksheet()->getDataValidation($this->getCoordinate());
404 - }
405 + return $this->getWorksheet()->getDataValidation($this->getCoordinate());
406 + }
405 407
406 - /**
407 - * Set Data validation rules
408 - *
409 - * @param PHPExcel_Cell_DataValidation $pDataValidation
410 - * @return PHPExcel_Cell
411 - * @throws PHPExcel_Exception
412 - */
413 - public function setDataValidation(PHPExcel_Cell_DataValidation $pDataValidation = null)
414 - {
415 - if (!isset($this->parent)) {
416 - throw new PHPExcel_Exception('Cannot set data validation for cell that is not bound to a worksheet');
417 - }
408 + /**
409 + * Set Data validation rules
410 + *
411 + * @param PHPExcel_Cell_DataValidation $pDataValidation
412 + * @return PHPExcel_Cell
413 + * @throws PHPExcel_Exception
414 + */
415 + public function setDataValidation(PHPExcel_Cell_DataValidation $pDataValidation = NULL)
416 + {
417 + if (!isset($this->_parent)) {
418 + throw new PHPExcel_Exception('Cannot set data validation for cell that is not bound to a worksheet');
419 + }
418 420
419 - $this->getWorksheet()->setDataValidation($this->getCoordinate(), $pDataValidation);
421 + $this->getWorksheet()->setDataValidation($this->getCoordinate(), $pDataValidation);
420 422
421 - return $this->notifyCacheController();
422 - }
423 + return $this->notifyCacheController();
424 + }
423 425
424 - /**
425 - * Does this cell contain a Hyperlink?
426 - *
427 - * @return boolean
428 - * @throws PHPExcel_Exception
429 - */
430 - public function hasHyperlink()
431 - {
432 - if (!isset($this->parent)) {
433 - throw new PHPExcel_Exception('Cannot check for hyperlink when cell is not bound to a worksheet');
434 - }
426 + /**
427 + * Does this cell contain a Hyperlink?
428 + *
429 + * @return boolean
430 + * @throws PHPExcel_Exception
431 + */
432 + public function hasHyperlink()
433 + {
434 + if (!isset($this->_parent)) {
435 + throw new PHPExcel_Exception('Cannot check for hyperlink when cell is not bound to a worksheet');
436 + }
435 437
436 - return $this->getWorksheet()->hyperlinkExists($this->getCoordinate());
437 - }
438 + return $this->getWorksheet()->hyperlinkExists($this->getCoordinate());
439 + }
438 440
439 - /**
440 - * Get Hyperlink
441 - *
442 - * @return PHPExcel_Cell_Hyperlink
443 - * @throws PHPExcel_Exception
444 - */
445 - public function getHyperlink()
446 - {
447 - if (!isset($this->parent)) {
448 - throw new PHPExcel_Exception('Cannot get hyperlink for cell that is not bound to a worksheet');
449 - }
441 + /**
442 + * Get Hyperlink
443 + *
444 + * @return PHPExcel_Cell_Hyperlink
445 + * @throws PHPExcel_Exception
446 + */
447 + public function getHyperlink()
448 + {
449 + if (!isset($this->_parent)) {
450 + throw new PHPExcel_Exception('Cannot get hyperlink for cell that is not bound to a worksheet');
451 + }
450 452
451 - return $this->getWorksheet()->getHyperlink($this->getCoordinate());
452 - }
453 + return $this->getWorksheet()->getHyperlink($this->getCoordinate());
454 + }
453 455
454 - /**
455 - * Set Hyperlink
456 - *
457 - * @param PHPExcel_Cell_Hyperlink $pHyperlink
458 - * @return PHPExcel_Cell
459 - * @throws PHPExcel_Exception
460 - */
461 - public function setHyperlink(PHPExcel_Cell_Hyperlink $pHyperlink = null)
462 - {
463 - if (!isset($this->parent)) {
464 - throw new PHPExcel_Exception('Cannot set hyperlink for cell that is not bound to a worksheet');
465 - }
456 + /**
457 + * Set Hyperlink
458 + *
459 + * @param PHPExcel_Cell_Hyperlink $pHyperlink
460 + * @return PHPExcel_Cell
461 + * @throws PHPExcel_Exception
462 + */
463 + public function setHyperlink(PHPExcel_Cell_Hyperlink $pHyperlink = NULL)
464 + {
465 + if (!isset($this->_parent)) {
466 + throw new PHPExcel_Exception('Cannot set hyperlink for cell that is not bound to a worksheet');
467 + }
466 468
467 - $this->getWorksheet()->setHyperlink($this->getCoordinate(), $pHyperlink);
469 + $this->getWorksheet()->setHyperlink($this->getCoordinate(), $pHyperlink);
468 470
469 - return $this->notifyCacheController();
470 - }
471 + return $this->notifyCacheController();
472 + }
471 473
472 - /**
473 - * Get parent worksheet
474 - *
475 - * @return PHPExcel_CachedObjectStorage_CacheBase
476 - */
477 - public function getParent()
478 - {
479 - return $this->parent;
480 - }
474 + /**
475 + * Get parent worksheet
476 + *
477 + * @return PHPExcel_CachedObjectStorage_CacheBase
478 + */
479 + public function getParent() {
480 + return $this->_parent;
481 + }
481 482
482 - /**
483 - * Get parent worksheet
484 - *
485 - * @return PHPExcel_Worksheet
486 - */
487 - public function getWorksheet()
488 - {
489 - return $this->parent->getParent();
490 - }
483 + /**
484 + * Get parent worksheet
485 + *
486 + * @return PHPExcel_Worksheet
487 + */
488 + public function getWorksheet() {
489 + return $this->_parent->getParent();
490 + }
491 491
492 - /**
493 - * Is this cell in a merge range
494 - *
495 - * @return boolean
496 - */
497 - public function isInMergeRange()
498 - {
492 + /**
493 + * Is this cell in a merge range
494 + *
495 + * @return boolean
496 + */
497 + public function isInMergeRange() {
499 498 return (boolean) $this->getMergeRange();
500 499 }
501 500
502 - /**
503 - * Is this cell the master (top left cell) in a merge range (that holds the actual data value)
504 - *
505 - * @return boolean
506 - */
507 - public function isMergeRangeValueCell()
508 - {
501 + /**
502 + * Is this cell the master (top left cell) in a merge range (that holds the actual data value)
503 + *
504 + * @return boolean
505 + */
506 + public function isMergeRangeValueCell() {
509 507 if ($mergeRange = $this->getMergeRange()) {
510 508 $mergeRange = PHPExcel_Cell::splitRange($mergeRange);
511 509 list($startCell) = $mergeRange[0];
512 510 if ($this->getCoordinate() === $startCell) {
@@ -515,16 +513,15 @@
515 513 }
516 514 return false;
517 515 }
518 516
519 - /**
520 - * If this cell is in a merge range, then return the range
521 - *
522 - * @return string
523 - */
524 - public function getMergeRange()
525 - {
526 - foreach ($this->getWorksheet()->getMergeCells() as $mergeRange) {
517 + /**
518 + * If this cell is in a merge range, then return the range
519 + *
520 + * @return string
521 + */
522 + public function getMergeRange() {
523 + foreach($this->getWorksheet()->getMergeCells() as $mergeRange) {
527 524 if ($this->isInRange($mergeRange)) {
528 525 return $mergeRange;
529 526 }
530 527 }
@@ -530,503 +527,496 @@
530 527 }
531 528 return false;
532 529 }
533 530
534 - /**
535 - * Get cell style
536 - *
537 - * @return PHPExcel_Style
538 - */
539 - public function getStyle()
540 - {
541 - return $this->getWorksheet()->getStyle($this->getCoordinate());
542 - }
531 + /**
532 + * Get cell style
533 + *
534 + * @return PHPExcel_Style
535 + */
536 + public function getStyle()
537 + {
538 + return $this->getWorksheet()->getStyle($this->getCoordinate());
539 + }
543 540
544 - /**
545 - * Re-bind parent
546 - *
547 - * @param PHPExcel_Worksheet $parent
548 - * @return PHPExcel_Cell
549 - */
550 - public function rebindParent(PHPExcel_Worksheet $parent)
551 - {
552 - $this->parent = $parent->getCellCacheController();
541 + /**
542 + * Re-bind parent
543 + *
544 + * @param PHPExcel_Worksheet $parent
545 + * @return PHPExcel_Cell
546 + */
547 + public function rebindParent(PHPExcel_Worksheet $parent) {
548 + $this->_parent = $parent->getCellCacheController();
553 549
554 - return $this->notifyCacheController();
555 - }
550 + return $this->notifyCacheController();
551 + }
556 552
557 - /**
558 - * Is cell in a specific range?
559 - *
560 - * @param string $pRange Cell range (e.g. A1:A1)
561 - * @return boolean
562 - */
563 - public function isInRange($pRange = 'A1:A1')
564 - {
565 - list($rangeStart, $rangeEnd) = self::rangeBoundaries($pRange);
553 + /**
554 + * Is cell in a specific range?
555 + *
556 + * @param string $pRange Cell range (e.g. A1:A1)
557 + * @return boolean
558 + */
559 + public function isInRange($pRange = 'A1:A1')
560 + {
561 + list($rangeStart,$rangeEnd) = self::rangeBoundaries($pRange);
566 562
567 - // Translate properties
568 - $myColumn = self::columnIndexFromString($this->getColumn());
569 - $myRow = $this->getRow();
563 + // Translate properties
564 + $myColumn = self::columnIndexFromString($this->getColumn());
565 + $myRow = $this->getRow();
570 566
571 - // Verify if cell is in range
572 - return (($rangeStart[0] <= $myColumn) && ($rangeEnd[0] >= $myColumn) &&
573 - ($rangeStart[1] <= $myRow) && ($rangeEnd[1] >= $myRow)
574 - );
575 - }
567 + // Verify if cell is in range
568 + return (($rangeStart[0] <= $myColumn) && ($rangeEnd[0] >= $myColumn) &&
569 + ($rangeStart[1] <= $myRow) && ($rangeEnd[1] >= $myRow)
570 + );
571 + }
576 572
577 - /**
578 - * Coordinate from string
579 - *
580 - * @param string $pCoordinateString
581 - * @return array Array containing column and row (indexes 0 and 1)
582 - * @throws PHPExcel_Exception
583 - */
584 - public static function coordinateFromString($pCoordinateString = 'A1')
585 - {
586 - if (preg_match("/^([$]?[A-Z]{1,3})([$]?\d{1,7})$/", $pCoordinateString, $matches)) {
587 - return array($matches[1],$matches[2]);
588 - } elseif ((strpos($pCoordinateString, ':') !== false) || (strpos($pCoordinateString, ',') !== false)) {
589 - throw new PHPExcel_Exception('Cell coordinate string can not be a range of cells');
590 - } elseif ($pCoordinateString == '') {
591 - throw new PHPExcel_Exception('Cell coordinate can not be zero-length string');
592 - }
573 + /**
574 + * Coordinate from string
575 + *
576 + * @param string $pCoordinateString
577 + * @return array Array containing column and row (indexes 0 and 1)
578 + * @throws PHPExcel_Exception
579 + */
580 + public static function coordinateFromString($pCoordinateString = 'A1')
581 + {
582 + if (preg_match("/^([$]?[A-Z]{1,3})([$]?\d{1,7})$/", $pCoordinateString, $matches)) {
583 + return array($matches[1],$matches[2]);
584 + } elseif ((strpos($pCoordinateString,':') !== FALSE) || (strpos($pCoordinateString,',') !== FALSE)) {
585 + throw new PHPExcel_Exception('Cell coordinate string can not be a range of cells');
586 + } elseif ($pCoordinateString == '') {
587 + throw new PHPExcel_Exception('Cell coordinate can not be zero-length string');
588 + }
593 589
594 - throw new PHPExcel_Exception('Invalid cell coordinate '.$pCoordinateString);
595 - }
590 + throw new PHPExcel_Exception('Invalid cell coordinate '.$pCoordinateString);
591 + }
596 592
597 - /**
598 - * Make string row, column or cell coordinate absolute
599 - *
600 - * @param string $pCoordinateString e.g. 'A' or '1' or 'A1'
601 - * Note that this value can be a row or column reference as well as a cell reference
602 - * @return string Absolute coordinate e.g. '$A' or '$1' or '$A$1'
603 - * @throws PHPExcel_Exception
604 - */
605 - public static function absoluteReference($pCoordinateString = 'A1')
606 - {
607 - if (strpos($pCoordinateString, ':') === false && strpos($pCoordinateString, ',') === false) {
608 - // Split out any worksheet name from the reference
609 - $worksheet = '';
610 - $cellAddress = explode('!', $pCoordinateString);
611 - if (count($cellAddress) > 1) {
612 - list($worksheet, $pCoordinateString) = $cellAddress;
613 - }
614 - if ($worksheet > '') {
615 - $worksheet .= '!';
616 - }
593 + /**
594 + * Make string row, column or cell coordinate absolute
595 + *
596 + * @param string $pCoordinateString e.g. 'A' or '1' or 'A1'
597 + * Note that this value can be a row or column reference as well as a cell reference
598 + * @return string Absolute coordinate e.g. '$A' or '$1' or '$A$1'
599 + * @throws PHPExcel_Exception
600 + */
601 + public static function absoluteReference($pCoordinateString = 'A1')
602 + {
603 + if (strpos($pCoordinateString,':') === FALSE && strpos($pCoordinateString,',') === FALSE) {
604 + // Split out any worksheet name from the reference
605 + $worksheet = '';
606 + $cellAddress = explode('!',$pCoordinateString);
607 + if (count($cellAddress) > 1) {
608 + list($worksheet,$pCoordinateString) = $cellAddress;
609 + }
610 + if ($worksheet > '') $worksheet .= '!';
617 611
618 - // Create absolute coordinate
619 - if (ctype_digit($pCoordinateString)) {
620 - return $worksheet . '$' . $pCoordinateString;
621 - } elseif (ctype_alpha($pCoordinateString)) {
622 - return $worksheet . '$' . strtoupper($pCoordinateString);
623 - }
624 - return $worksheet . self::absoluteCoordinate($pCoordinateString);
625 - }
612 + // Create absolute coordinate
613 + if (ctype_digit($pCoordinateString)) {
614 + return $worksheet . '$' . $pCoordinateString;
615 + } elseif (ctype_alpha($pCoordinateString)) {
616 + return $worksheet . '$' . strtoupper($pCoordinateString);
617 + }
618 + return $worksheet . self::absoluteCoordinate($pCoordinateString);
619 + }
626 620
627 - throw new PHPExcel_Exception('Cell coordinate string can not be a range of cells');
628 - }
621 + throw new PHPExcel_Exception('Cell coordinate string can not be a range of cells');
622 + }
629 623
630 - /**
631 - * Make string coordinate absolute
632 - *
633 - * @param string $pCoordinateString e.g. 'A1'
634 - * @return string Absolute coordinate e.g. '$A$1'
635 - * @throws PHPExcel_Exception
636 - */
637 - public static function absoluteCoordinate($pCoordinateString = 'A1')
638 - {
639 - if (strpos($pCoordinateString, ':') === false && strpos($pCoordinateString, ',') === false) {
640 - // Split out any worksheet name from the coordinate
641 - $worksheet = '';
642 - $cellAddress = explode('!', $pCoordinateString);
643 - if (count($cellAddress) > 1) {
644 - list($worksheet, $pCoordinateString) = $cellAddress;
645 - }
646 - if ($worksheet > '') {
647 - $worksheet .= '!';
648 - }
624 + /**
625 + * Make string coordinate absolute
626 + *
627 + * @param string $pCoordinateString e.g. 'A1'
628 + * @return string Absolute coordinate e.g. '$A$1'
629 + * @throws PHPExcel_Exception
630 + */
631 + public static function absoluteCoordinate($pCoordinateString = 'A1')
632 + {
633 + if (strpos($pCoordinateString,':') === FALSE && strpos($pCoordinateString,',') === FALSE) {
634 + // Split out any worksheet name from the coordinate
635 + $worksheet = '';
636 + $cellAddress = explode('!',$pCoordinateString);
637 + if (count($cellAddress) > 1) {
638 + list($worksheet,$pCoordinateString) = $cellAddress;
639 + }
640 + if ($worksheet > '') $worksheet .= '!';
649 641
650 - // Create absolute coordinate
651 - list($column, $row) = self::coordinateFromString($pCoordinateString);
652 - $column = ltrim($column, '$');
653 - $row = ltrim($row, '$');
654 - return $worksheet . '$' . $column . '$' . $row;
655 - }
642 + // Create absolute coordinate
643 + list($column, $row) = self::coordinateFromString($pCoordinateString);
644 + $column = ltrim($column,'$');
645 + $row = ltrim($row,'$');
646 + return $worksheet . '$' . $column . '$' . $row;
647 + }
656 648
657 - throw new PHPExcel_Exception('Cell coordinate string can not be a range of cells');
658 - }
649 + throw new PHPExcel_Exception('Cell coordinate string can not be a range of cells');
650 + }
659 651
660 - /**
661 - * Split range into coordinate strings
662 - *
663 - * @param string $pRange e.g. 'B4:D9' or 'B4:D9,H2:O11' or 'B4'
664 - * @return array Array containg one or more arrays containing one or two coordinate strings
665 - * e.g. array('B4','D9') or array(array('B4','D9'),array('H2','O11'))
666 - * or array('B4')
667 - */
668 - public static function splitRange($pRange = 'A1:A1')
669 - {
670 - // Ensure $pRange is a valid range
671 - if (empty($pRange)) {
672 - $pRange = self::DEFAULT_RANGE;
673 - }
652 + /**
653 + * Split range into coordinate strings
654 + *
655 + * @param string $pRange e.g. 'B4:D9' or 'B4:D9,H2:O11' or 'B4'
656 + * @return array Array containg one or more arrays containing one or two coordinate strings
657 + * e.g. array('B4','D9') or array(array('B4','D9'),array('H2','O11'))
658 + * or array('B4')
659 + */
660 + public static function splitRange($pRange = 'A1:A1')
661 + {
662 + // Ensure $pRange is a valid range
663 + if(empty($pRange)) {
664 + $pRange = self::DEFAULT_RANGE;
665 + }
674 666
675 - $exploded = explode(',', $pRange);
676 - $counter = count($exploded);
677 - for ($i = 0; $i < $counter; ++$i) {
678 - $exploded[$i] = explode(':', $exploded[$i]);
679 - }
680 - return $exploded;
681 - }
667 + $exploded = explode(',', $pRange);
668 + $counter = count($exploded);
669 + for ($i = 0; $i < $counter; ++$i) {
670 + $exploded[$i] = explode(':', $exploded[$i]);
671 + }
672 + return $exploded;
673 + }
682 674
683 - /**
684 - * Build range from coordinate strings
685 - *
686 - * @param array $pRange Array containg one or more arrays containing one or two coordinate strings
687 - * @return string String representation of $pRange
688 - * @throws PHPExcel_Exception
689 - */
690 - public static function buildRange($pRange)
691 - {
692 - // Verify range
693 - if (!is_array($pRange) || empty($pRange) || !is_array($pRange[0])) {
694 - throw new PHPExcel_Exception('Range does not contain any information');
695 - }
675 + /**
676 + * Build range from coordinate strings
677 + *
678 + * @param array $pRange Array containg one or more arrays containing one or two coordinate strings
679 + * @return string String representation of $pRange
680 + * @throws PHPExcel_Exception
681 + */
682 + public static function buildRange($pRange)
683 + {
684 + // Verify range
685 + if (!is_array($pRange) || empty($pRange) || !is_array($pRange[0])) {
686 + throw new PHPExcel_Exception('Range does not contain any information');
687 + }
696 688
697 - // Build range
698 - $imploded = array();
699 - $counter = count($pRange);
700 - for ($i = 0; $i < $counter; ++$i) {
701 - $pRange[$i] = implode(':', $pRange[$i]);
702 - }
703 - $imploded = implode(',', $pRange);
689 + // Build range
690 + $imploded = array();
691 + $counter = count($pRange);
692 + for ($i = 0; $i < $counter; ++$i) {
693 + $pRange[$i] = implode(':', $pRange[$i]);
694 + }
695 + $imploded = implode(',', $pRange);
704 696
705 - return $imploded;
706 - }
697 + return $imploded;
698 + }
707 699
708 - /**
709 - * Calculate range boundaries
710 - *
711 - * @param string $pRange Cell range (e.g. A1:A1)
712 - * @return array Range coordinates array(Start Cell, End Cell)
713 - * where Start Cell and End Cell are arrays (Column Number, Row Number)
714 - */
715 - public static function rangeBoundaries($pRange = 'A1:A1')
716 - {
717 - // Ensure $pRange is a valid range
718 - if (empty($pRange)) {
719 - $pRange = self::DEFAULT_RANGE;
720 - }
700 + /**
701 + * Calculate range boundaries
702 + *
703 + * @param string $pRange Cell range (e.g. A1:A1)
704 + * @return array Range coordinates array(Start Cell, End Cell)
705 + * where Start Cell and End Cell are arrays (Column Number, Row Number)
706 + */
707 + public static function rangeBoundaries($pRange = 'A1:A1')
708 + {
709 + // Ensure $pRange is a valid range
710 + if(empty($pRange)) {
711 + $pRange = self::DEFAULT_RANGE;
712 + }
721 713
722 - // Uppercase coordinate
723 - $pRange = strtoupper($pRange);
714 + // Uppercase coordinate
715 + $pRange = strtoupper($pRange);
724 716
725 - // Extract range
726 - if (strpos($pRange, ':') === false) {
727 - $rangeA = $rangeB = $pRange;
728 - } else {
729 - list($rangeA, $rangeB) = explode(':', $pRange);
730 - }
717 + // Extract range
718 + if (strpos($pRange, ':') === FALSE) {
719 + $rangeA = $rangeB = $pRange;
720 + } else {
721 + list($rangeA, $rangeB) = explode(':', $pRange);
722 + }
731 723
732 - // Calculate range outer borders
733 - $rangeStart = self::coordinateFromString($rangeA);
734 - $rangeEnd = self::coordinateFromString($rangeB);
724 + // Calculate range outer borders
725 + $rangeStart = self::coordinateFromString($rangeA);
726 + $rangeEnd = self::coordinateFromString($rangeB);
735 727
736 - // Translate column into index
737 - $rangeStart[0] = self::columnIndexFromString($rangeStart[0]);
738 - $rangeEnd[0] = self::columnIndexFromString($rangeEnd[0]);
728 + // Translate column into index
729 + $rangeStart[0] = self::columnIndexFromString($rangeStart[0]);
730 + $rangeEnd[0] = self::columnIndexFromString($rangeEnd[0]);
739 731
740 - return array($rangeStart, $rangeEnd);
741 - }
732 + return array($rangeStart, $rangeEnd);
733 + }
742 734
743 - /**
744 - * Calculate range dimension
745 - *
746 - * @param string $pRange Cell range (e.g. A1:A1)
747 - * @return array Range dimension (width, height)
748 - */
749 - public static function rangeDimension($pRange = 'A1:A1')
750 - {
751 - // Calculate range outer borders
752 - list($rangeStart, $rangeEnd) = self::rangeBoundaries($pRange);
735 + /**
736 + * Calculate range dimension
737 + *
738 + * @param string $pRange Cell range (e.g. A1:A1)
739 + * @return array Range dimension (width, height)
740 + */
741 + public static function rangeDimension($pRange = 'A1:A1')
742 + {
743 + // Calculate range outer borders
744 + list($rangeStart,$rangeEnd) = self::rangeBoundaries($pRange);
753 745
754 - return array( ($rangeEnd[0] - $rangeStart[0] + 1), ($rangeEnd[1] - $rangeStart[1] + 1) );
755 - }
746 + return array( ($rangeEnd[0] - $rangeStart[0] + 1), ($rangeEnd[1] - $rangeStart[1] + 1) );
747 + }
756 748
757 - /**
758 - * Calculate range boundaries
759 - *
760 - * @param string $pRange Cell range (e.g. A1:A1)
761 - * @return array Range coordinates array(Start Cell, End Cell)
762 - * where Start Cell and End Cell are arrays (Column ID, Row Number)
763 - */
764 - public static function getRangeBoundaries($pRange = 'A1:A1')
765 - {
766 - // Ensure $pRange is a valid range
767 - if (empty($pRange)) {
768 - $pRange = self::DEFAULT_RANGE;
769 - }
749 + /**
750 + * Calculate range boundaries
751 + *
752 + * @param string $pRange Cell range (e.g. A1:A1)
753 + * @return array Range coordinates array(Start Cell, End Cell)
754 + * where Start Cell and End Cell are arrays (Column ID, Row Number)
755 + */
756 + public static function getRangeBoundaries($pRange = 'A1:A1')
757 + {
758 + // Ensure $pRange is a valid range
759 + if(empty($pRange)) {
760 + $pRange = self::DEFAULT_RANGE;
761 + }
770 762
771 - // Uppercase coordinate
772 - $pRange = strtoupper($pRange);
763 + // Uppercase coordinate
764 + $pRange = strtoupper($pRange);
773 765
774 - // Extract range
775 - if (strpos($pRange, ':') === false) {
776 - $rangeA = $rangeB = $pRange;
777 - } else {
778 - list($rangeA, $rangeB) = explode(':', $pRange);
779 - }
766 + // Extract range
767 + if (strpos($pRange, ':') === FALSE) {
768 + $rangeA = $rangeB = $pRange;
769 + } else {
770 + list($rangeA, $rangeB) = explode(':', $pRange);
771 + }
780 772
781 - return array( self::coordinateFromString($rangeA), self::coordinateFromString($rangeB));
782 - }
773 + return array( self::coordinateFromString($rangeA), self::coordinateFromString($rangeB));
774 + }
783 775
784 - /**
785 - * Column index from string
786 - *
787 - * @param string $pString
788 - * @return int Column index (base 1 !!!)
789 - */
790 - public static function columnIndexFromString($pString = 'A')
791 - {
792 - // Using a lookup cache adds a slight memory overhead, but boosts speed
793 - // caching using a static within the method is faster than a class static,
794 - // though it's additional memory overhead
795 - static $_indexCache = array();
776 + /**
777 + * Column index from string
778 + *
779 + * @param string $pString
780 + * @return int Column index (base 1 !!!)
781 + */
782 + public static function columnIndexFromString($pString = 'A')
783 + {
784 + // Using a lookup cache adds a slight memory overhead, but boosts speed
785 + // caching using a static within the method is faster than a class static,
786 + // though it's additional memory overhead
787 + static $_indexCache = array();
796 788
797 - if (isset($_indexCache[$pString])) {
798 - return $_indexCache[$pString];
799 - }
800 - // It's surprising how costly the strtoupper() and ord() calls actually are, so we use a lookup array rather than use ord()
801 - // and make it case insensitive to get rid of the strtoupper() as well. Because it's a static, there's no significant
802 - // memory overhead either
803 - static $_columnLookup = array(
804 - 'A' => 1, 'B' => 2, 'C' => 3, 'D' => 4, 'E' => 5, 'F' => 6, 'G' => 7, 'H' => 8, 'I' => 9, 'J' => 10, 'K' => 11, 'L' => 12, 'M' => 13,
805 - 'N' => 14, 'O' => 15, 'P' => 16, 'Q' => 17, 'R' => 18, 'S' => 19, 'T' => 20, 'U' => 21, 'V' => 22, 'W' => 23, 'X' => 24, 'Y' => 25, 'Z' => 26,
806 - 'a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5, 'f' => 6, 'g' => 7, 'h' => 8, 'i' => 9, 'j' => 10, 'k' => 11, 'l' => 12, 'm' => 13,
807 - 'n' => 14, 'o' => 15, 'p' => 16, 'q' => 17, 'r' => 18, 's' => 19, 't' => 20, 'u' => 21, 'v' => 22, 'w' => 23, 'x' => 24, 'y' => 25, 'z' => 26
808 - );
789 + if (isset($_indexCache[$pString]))
790 + return $_indexCache[$pString];
809 791
810 - // We also use the language construct isset() rather than the more costly strlen() function to match the length of $pString
811 - // for improved performance
812 - if (isset($pString{0})) {
813 - if (!isset($pString{1})) {
814 - $_indexCache[$pString] = $_columnLookup[$pString];
815 - return $_indexCache[$pString];
816 - } elseif (!isset($pString{2})) {
817 - $_indexCache[$pString] = $_columnLookup[$pString{0}] * 26 + $_columnLookup[$pString{1}];
818 - return $_indexCache[$pString];
819 - } elseif (!isset($pString{3})) {
820 - $_indexCache[$pString] = $_columnLookup[$pString{0}] * 676 + $_columnLookup[$pString{1}] * 26 + $_columnLookup[$pString{2}];
821 - return $_indexCache[$pString];
822 - }
823 - }
824 - throw new PHPExcel_Exception("Column string index can not be " . ((isset($pString{0})) ? "longer than 3 characters" : "empty"));
825 - }
792 + // It's surprising how costly the strtoupper() and ord() calls actually are, so we use a lookup array rather than use ord()
793 + // and make it case insensitive to get rid of the strtoupper() as well. Because it's a static, there's no significant
794 + // memory overhead either
795 + static $_columnLookup = array(
796 + 'A' => 1, 'B' => 2, 'C' => 3, 'D' => 4, 'E' => 5, 'F' => 6, 'G' => 7, 'H' => 8, 'I' => 9, 'J' => 10, 'K' => 11, 'L' => 12, 'M' => 13,
797 + 'N' => 14, 'O' => 15, 'P' => 16, 'Q' => 17, 'R' => 18, 'S' => 19, 'T' => 20, 'U' => 21, 'V' => 22, 'W' => 23, 'X' => 24, 'Y' => 25, 'Z' => 26,
798 + 'a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5, 'f' => 6, 'g' => 7, 'h' => 8, 'i' => 9, 'j' => 10, 'k' => 11, 'l' => 12, 'm' => 13,
799 + 'n' => 14, 'o' => 15, 'p' => 16, 'q' => 17, 'r' => 18, 's' => 19, 't' => 20, 'u' => 21, 'v' => 22, 'w' => 23, 'x' => 24, 'y' => 25, 'z' => 26
800 + );
826 801
827 - /**
828 - * String from columnindex
829 - *
830 - * @param int $pColumnIndex Column index (base 0 !!!)
831 - * @return string
832 - */
833 - public static function stringFromColumnIndex($pColumnIndex = 0)
834 - {
835 - // Using a lookup cache adds a slight memory overhead, but boosts speed
836 - // caching using a static within the method is faster than a class static,
837 - // though it's additional memory overhead
838 - static $_indexCache = array();
802 + // We also use the language construct isset() rather than the more costly strlen() function to match the length of $pString
803 + // for improved performance
804 + if (isset($pString{0})) {
805 + if (!isset($pString{1})) {
806 + $_indexCache[$pString] = $_columnLookup[$pString];
807 + return $_indexCache[$pString];
808 + } elseif(!isset($pString{2})) {
809 + $_indexCache[$pString] = $_columnLookup[$pString{0}] * 26 + $_columnLookup[$pString{1}];
810 + return $_indexCache[$pString];
811 + } elseif(!isset($pString{3})) {
812 + $_indexCache[$pString] = $_columnLookup[$pString{0}] * 676 + $_columnLookup[$pString{1}] * 26 + $_columnLookup[$pString{2}];
813 + return $_indexCache[$pString];
814 + }
815 + }
816 + throw new PHPExcel_Exception("Column string index can not be " . ((isset($pString{0})) ? "longer than 3 characters" : "empty"));
817 + }
839 818
840 - if (!isset($_indexCache[$pColumnIndex])) {
841 - // Determine column string
842 - if ($pColumnIndex < 26) {
843 - $_indexCache[$pColumnIndex] = chr(65 + $pColumnIndex);
844 - } elseif ($pColumnIndex < 702) {
845 - $_indexCache[$pColumnIndex] = chr(64 + ($pColumnIndex / 26)) .
846 - chr(65 + $pColumnIndex % 26);
847 - } else {
848 - $_indexCache[$pColumnIndex] = chr(64 + (($pColumnIndex - 26) / 676)) .
849 - chr(65 + ((($pColumnIndex - 26) % 676) / 26)) .
850 - chr(65 + $pColumnIndex % 26);
851 - }
852 - }
853 - return $_indexCache[$pColumnIndex];
854 - }
819 + /**
820 + * String from columnindex
821 + *
822 + * @param int $pColumnIndex Column index (base 0 !!!)
823 + * @return string
824 + */
825 + public static function stringFromColumnIndex($pColumnIndex = 0)
826 + {
827 + // Using a lookup cache adds a slight memory overhead, but boosts speed
828 + // caching using a static within the method is faster than a class static,
829 + // though it's additional memory overhead
830 + static $_indexCache = array();
855 831
856 - /**
857 - * Extract all cell references in range
858 - *
859 - * @param string $pRange Range (e.g. A1 or A1:C10 or A1:E10 A20:E25)
860 - * @return array Array containing single cell references
861 - */
862 - public static function extractAllCellReferencesInRange($pRange = 'A1')
863 - {
864 - // Returnvalue
865 - $returnValue = array();
832 + if (!isset($_indexCache[$pColumnIndex])) {
833 + // Determine column string
834 + if ($pColumnIndex < 26) {
835 + $_indexCache[$pColumnIndex] = chr(65 + $pColumnIndex);
836 + } elseif ($pColumnIndex < 702) {
837 + $_indexCache[$pColumnIndex] = chr(64 + ($pColumnIndex / 26)) .
838 + chr(65 + $pColumnIndex % 26);
839 + } else {
840 + $_indexCache[$pColumnIndex] = chr(64 + (($pColumnIndex - 26) / 676)) .
841 + chr(65 + ((($pColumnIndex - 26) % 676) / 26)) .
842 + chr(65 + $pColumnIndex % 26);
843 + }
844 + }
845 + return $_indexCache[$pColumnIndex];
846 + }
866 847
867 - // Explode spaces
868 - $cellBlocks = explode(' ', str_replace('$', '', strtoupper($pRange)));
869 - foreach ($cellBlocks as $cellBlock) {
870 - // Single cell?
871 - if (strpos($cellBlock, ':') === false && strpos($cellBlock, ',') === false) {
872 - $returnValue[] = $cellBlock;
873 - continue;
874 - }
848 + /**
849 + * Extract all cell references in range
850 + *
851 + * @param string $pRange Range (e.g. A1 or A1:C10 or A1:E10 A20:E25)
852 + * @return array Array containing single cell references
853 + */
854 + public static function extractAllCellReferencesInRange($pRange = 'A1') {
855 + // Returnvalue
856 + $returnValue = array();
875 857
876 - // Range...
877 - $ranges = self::splitRange($cellBlock);
878 - foreach ($ranges as $range) {
879 - // Single cell?
880 - if (!isset($range[1])) {
881 - $returnValue[] = $range[0];
882 - continue;
883 - }
858 + // Explode spaces
859 + $cellBlocks = explode(' ', str_replace('$', '', strtoupper($pRange)));
860 + foreach ($cellBlocks as $cellBlock) {
861 + // Single cell?
862 + if (strpos($cellBlock,':') === FALSE && strpos($cellBlock,',') === FALSE) {
863 + $returnValue[] = $cellBlock;
864 + continue;
865 + }
884 866
885 - // Range...
886 - list($rangeStart, $rangeEnd) = $range;
887 - sscanf($rangeStart, '%[A-Z]%d', $startCol, $startRow);
888 - sscanf($rangeEnd, '%[A-Z]%d', $endCol, $endRow);
889 - ++$endCol;
867 + // Range...
868 + $ranges = self::splitRange($cellBlock);
869 + foreach($ranges as $range) {
870 + // Single cell?
871 + if (!isset($range[1])) {
872 + $returnValue[] = $range[0];
873 + continue;
874 + }
890 875
891 - // Current data
892 - $currentCol = $startCol;
893 - $currentRow = $startRow;
876 + // Range...
877 + list($rangeStart, $rangeEnd) = $range;
878 + sscanf($rangeStart,'%[A-Z]%d', $startCol, $startRow);
879 + sscanf($rangeEnd,'%[A-Z]%d', $endCol, $endRow);
880 + $endCol++;
894 881
895 - // Loop cells
896 - while ($currentCol != $endCol) {
897 - while ($currentRow <= $endRow) {
898 - $returnValue[] = $currentCol.$currentRow;
899 - ++$currentRow;
900 - }
901 - ++$currentCol;
902 - $currentRow = $startRow;
903 - }
904 - }
905 - }
882 + // Current data
883 + $currentCol = $startCol;
884 + $currentRow = $startRow;
906 885
907 - // Sort the result by column and row
908 - $sortKeys = array();
909 - foreach (array_unique($returnValue) as $coord) {
910 - sscanf($coord, '%[A-Z]%d', $column, $row);
911 - $sortKeys[sprintf('%3s%09d', $column, $row)] = $coord;
912 - }
913 - ksort($sortKeys);
886 + // Loop cells
887 + while ($currentCol != $endCol) {
888 + while ($currentRow <= $endRow) {
889 + $returnValue[] = $currentCol.$currentRow;
890 + ++$currentRow;
891 + }
892 + ++$currentCol;
893 + $currentRow = $startRow;
894 + }
895 + }
896 + }
914 897
915 - // Return value
916 - return array_values($sortKeys);
917 - }
898 + // Sort the result by column and row
899 + $sortKeys = array();
900 + foreach (array_unique($returnValue) as $coord) {
901 + sscanf($coord,'%[A-Z]%d', $column, $row);
902 + $sortKeys[sprintf('%3s%09d',$column,$row)] = $coord;
903 + }
904 + ksort($sortKeys);
918 905
919 - /**
920 - * Compare 2 cells
921 - *
922 - * @param PHPExcel_Cell $a Cell a
923 - * @param PHPExcel_Cell $b Cell b
924 - * @return int Result of comparison (always -1 or 1, never zero!)
925 - */
926 - public static function compareCells(PHPExcel_Cell $a, PHPExcel_Cell $b)
927 - {
928 - if ($a->getRow() < $b->getRow()) {
929 - return -1;
930 - } elseif ($a->getRow() > $b->getRow()) {
931 - return 1;
932 - } elseif (self::columnIndexFromString($a->getColumn()) < self::columnIndexFromString($b->getColumn())) {
933 - return -1;
934 - } else {
935 - return 1;
936 - }
937 - }
906 + // Return value
907 + return array_values($sortKeys);
908 + }
938 909
939 - /**
940 - * Get value binder to use
941 - *
942 - * @return PHPExcel_Cell_IValueBinder
943 - */
944 - public static function getValueBinder()
945 - {
946 - if (self::$valueBinder === null) {
947 - self::$valueBinder = new PHPExcel_Cell_DefaultValueBinder();
948 - }
910 + /**
911 + * Compare 2 cells
912 + *
913 + * @param PHPExcel_Cell $a Cell a
914 + * @param PHPExcel_Cell $b Cell b
915 + * @return int Result of comparison (always -1 or 1, never zero!)
916 + */
917 + public static function compareCells(PHPExcel_Cell $a, PHPExcel_Cell $b)
918 + {
919 + if ($a->getRow() < $b->getRow()) {
920 + return -1;
921 + } elseif ($a->getRow() > $b->getRow()) {
922 + return 1;
923 + } elseif (self::columnIndexFromString($a->getColumn()) < self::columnIndexFromString($b->getColumn())) {
924 + return -1;
925 + } else {
926 + return 1;
927 + }
928 + }
949 929
950 - return self::$valueBinder;
951 - }
930 + /**
931 + * Get value binder to use
932 + *
933 + * @return PHPExcel_Cell_IValueBinder
934 + */
935 + public static function getValueBinder() {
936 + if (self::$_valueBinder === NULL) {
937 + self::$_valueBinder = new PHPExcel_Cell_DefaultValueBinder();
938 + }
952 939
953 - /**
954 - * Set value binder to use
955 - *
956 - * @param PHPExcel_Cell_IValueBinder $binder
957 - * @throws PHPExcel_Exception
958 - */
959 - public static function setValueBinder(PHPExcel_Cell_IValueBinder $binder = null)
960 - {
961 - if ($binder === null) {
962 - throw new PHPExcel_Exception("A PHPExcel_Cell_IValueBinder is required for PHPExcel to function correctly.");
963 - }
940 + return self::$_valueBinder;
941 + }
964 942
965 - self::$valueBinder = $binder;
966 - }
943 + /**
944 + * Set value binder to use
945 + *
946 + * @param PHPExcel_Cell_IValueBinder $binder
947 + * @throws PHPExcel_Exception
948 + */
949 + public static function setValueBinder(PHPExcel_Cell_IValueBinder $binder = NULL) {
950 + if ($binder === NULL) {
951 + throw new PHPExcel_Exception("A PHPExcel_Cell_IValueBinder is required for PHPExcel to function correctly.");
952 + }
967 953
968 - /**
969 - * Implement PHP __clone to create a deep clone, not just a shallow copy.
970 - */
971 - public function __clone()
972 - {
973 - $vars = get_object_vars($this);
974 - foreach ($vars as $key => $value) {
975 - if ((is_object($value)) && ($key != 'parent')) {
976 - $this->$key = clone $value;
977 - } else {
978 - $this->$key = $value;
979 - }
980 - }
981 - }
954 + self::$_valueBinder = $binder;
955 + }
982 956
983 - /**
984 - * Get index to cellXf
985 - *
986 - * @return int
987 - */
988 - public function getXfIndex()
989 - {
990 - return $this->xfIndex;
991 - }
957 + /**
958 + * Implement PHP __clone to create a deep clone, not just a shallow copy.
959 + */
960 + public function __clone() {
961 + $vars = get_object_vars($this);
962 + foreach ($vars as $key => $value) {
963 + if ((is_object($value)) && ($key != '_parent')) {
964 + $this->$key = clone $value;
965 + } else {
966 + $this->$key = $value;
967 + }
968 + }
969 + }
992 970
993 - /**
994 - * Set index to cellXf
995 - *
996 - * @param int $pValue
997 - * @return PHPExcel_Cell
998 - */
999 - public function setXfIndex($pValue = 0)
1000 - {
1001 - $this->xfIndex = $pValue;
971 + /**
972 + * Get index to cellXf
973 + *
974 + * @return int
975 + */
976 + public function getXfIndex()
977 + {
978 + return $this->_xfIndex;
979 + }
1002 980
1003 - return $this->notifyCacheController();
1004 - }
981 + /**
982 + * Set index to cellXf
983 + *
984 + * @param int $pValue
985 + * @return PHPExcel_Cell
986 + */
987 + public function setXfIndex($pValue = 0)
988 + {
989 + $this->_xfIndex = $pValue;
1005 990
1006 - /**
1007 - * @deprecated Since version 1.7.8 for planned changes to cell for array formula handling
1008 - */
1009 - public function setFormulaAttributes($pAttributes)
1010 - {
1011 - $this->formulaAttributes = $pAttributes;
1012 - return $this;
1013 - }
991 + return $this->notifyCacheController();
992 + }
1014 993
1015 - /**
1016 - * @deprecated Since version 1.7.8 for planned changes to cell for array formula handling
1017 - */
1018 - public function getFormulaAttributes()
1019 - {
1020 - return $this->formulaAttributes;
1021 - }
994 + /**
995 + * @deprecated Since version 1.7.8 for planned changes to cell for array formula handling
996 + */
997 + public function setFormulaAttributes($pAttributes)
998 + {
999 + $this->_formulaAttributes = $pAttributes;
1000 + return $this;
1001 + }
1022 1002
1003 + /**
1004 + * @deprecated Since version 1.7.8 for planned changes to cell for array formula handling
1005 + */
1006 + public function getFormulaAttributes()
1007 + {
1008 + return $this->_formulaAttributes;
1009 + }
1010 +
1023 1011 /**
1024 1012 * Convert to string
1025 1013 *
1026 1014 * @return string
1027 1015 */
1028 - public function __toString()
1029 - {
1030 - return (string) $this->getValue();
1031 - }
1016 + public function __toString()
1017 + {
1018 + return (string) $this->getValue();
1019 + }
1020 +
1032 1021 }
1022 +