PageRenderTime 51ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/framework/lib/classes/PHPExcel/Cell.php

https://bitbucket.org/designbyheart/original
PHP | 860 lines | 395 code | 105 blank | 360 comment | 64 complexity | 77eca4da81b4ad6161d00bcdfab00349 MD5 | raw file
Possible License(s): GPL-3.0
  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_Cell
  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. */
  27. /**
  28. * PHPExcel_Cell
  29. *
  30. * @category PHPExcel
  31. * @package PHPExcel_Cell
  32. * @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
  33. */
  34. class PHPExcel_Cell
  35. {
  36. /**
  37. * Value binder to use
  38. *
  39. * @var PHPExcel_Cell_IValueBinder
  40. */
  41. private static $_valueBinder = null;
  42. /**
  43. * Column of the cell
  44. *
  45. * @var string
  46. */
  47. private $_column;
  48. /**
  49. * Row of the cell
  50. *
  51. * @var int
  52. */
  53. private $_row;
  54. /**
  55. * Value of the cell
  56. *
  57. * @var mixed
  58. */
  59. private $_value;
  60. /**
  61. * Calculated value of the cell (used for caching)
  62. *
  63. * @var mixed
  64. */
  65. private $_calculatedValue = null;
  66. /**
  67. * Type of the cell data
  68. *
  69. * @var string
  70. */
  71. private $_dataType;
  72. /**
  73. * Parent worksheet
  74. *
  75. * @var PHPExcel_Worksheet
  76. */
  77. private $_parent;
  78. /**
  79. * Index to cellXf
  80. *
  81. * @var int
  82. */
  83. private $_xfIndex;
  84. /**
  85. * Attributes of the formula
  86. *
  87. *
  88. */
  89. private $_formulaAttributes;
  90. /**
  91. * Send notification to the cache controller
  92. * @return void
  93. **/
  94. public function notifyCacheController() {
  95. $this->_parent->getCellCacheController()->updateCacheData($this);
  96. return $this;
  97. }
  98. public function detach() {
  99. $this->_parent = null;
  100. }
  101. public function attach($parent) {
  102. $this->_parent = $parent;
  103. }
  104. /**
  105. * Create a new Cell
  106. *
  107. * @param string $pColumn
  108. * @param int $pRow
  109. * @param mixed $pValue
  110. * @param string $pDataType
  111. * @param PHPExcel_Worksheet $pSheet
  112. * @throws Exception
  113. */
  114. public function __construct($pColumn = 'A', $pRow = 1, $pValue = null, $pDataType = null, PHPExcel_Worksheet $pSheet = null)
  115. {
  116. // Initialise cell coordinate
  117. $this->_column = strtoupper($pColumn);
  118. $this->_row = $pRow;
  119. // Initialise cell value
  120. $this->_value = $pValue;
  121. // Set worksheet
  122. $this->_parent = $pSheet;
  123. // Set datatype?
  124. if ($pDataType !== null) {
  125. if ($pDataType == PHPExcel_Cell_DataType::TYPE_STRING2)
  126. $pDataType = PHPExcel_Cell_DataType::TYPE_STRING;
  127. $this->_dataType = $pDataType;
  128. } else {
  129. if (!self::getValueBinder()->bindValue($this, $pValue)) {
  130. throw new Exception("Value could not be bound to cell.");
  131. }
  132. }
  133. // set default index to cellXf
  134. $this->_xfIndex = 0;
  135. }
  136. /**
  137. * Get cell coordinate column
  138. *
  139. * @return string
  140. */
  141. public function getColumn()
  142. {
  143. return $this->_column;
  144. }
  145. /**
  146. * Get cell coordinate row
  147. *
  148. * @return int
  149. */
  150. public function getRow()
  151. {
  152. return $this->_row;
  153. }
  154. /**
  155. * Get cell coordinate
  156. *
  157. * @return string
  158. */
  159. public function getCoordinate()
  160. {
  161. return $this->_column . $this->_row;
  162. }
  163. /**
  164. * Get cell value
  165. *
  166. * @return mixed
  167. */
  168. public function getValue()
  169. {
  170. return $this->_value;
  171. }
  172. /**
  173. * Get cell value with formatting
  174. *
  175. * @return string
  176. */
  177. public function getFormattedValue()
  178. {
  179. return PHPExcel_Style_NumberFormat::toFormattedString( $this->getCalculatedValue(),
  180. $this->_parent->getParent()->getCellXfByIndex($this->getXfIndex())->getNumberFormat()->getFormatCode()
  181. );
  182. }
  183. /**
  184. * Set cell value
  185. *
  186. * This clears the cell formula.
  187. *
  188. * @param mixed $pValue Value
  189. * @return PHPExcel_Cell
  190. */
  191. public function setValue($pValue = null)
  192. {
  193. if (!self::getValueBinder()->bindValue($this, $pValue)) {
  194. throw new Exception("Value could not be bound to cell.");
  195. }
  196. return $this;
  197. }
  198. /**
  199. * Set cell value (with explicit data type given)
  200. *
  201. * @param mixed $pValue Value
  202. * @param string $pDataType Explicit data type
  203. * @return PHPExcel_Cell
  204. * @throws Exception
  205. */
  206. public function setValueExplicit($pValue = null, $pDataType = PHPExcel_Cell_DataType::TYPE_STRING)
  207. {
  208. // set the value according to data type
  209. switch ($pDataType) {
  210. case PHPExcel_Cell_DataType::TYPE_STRING2:
  211. $pDataType = PHPExcel_Cell_DataType::TYPE_STRING;
  212. case PHPExcel_Cell_DataType::TYPE_STRING:
  213. case PHPExcel_Cell_DataType::TYPE_NULL:
  214. case PHPExcel_Cell_DataType::TYPE_INLINE:
  215. $this->_value = PHPExcel_Cell_DataType::checkString($pValue);
  216. break;
  217. case PHPExcel_Cell_DataType::TYPE_NUMERIC:
  218. $this->_value = (float)$pValue;
  219. break;
  220. case PHPExcel_Cell_DataType::TYPE_FORMULA:
  221. $this->_value = (string)$pValue;
  222. break;
  223. case PHPExcel_Cell_DataType::TYPE_BOOL:
  224. $this->_value = (bool)$pValue;
  225. break;
  226. case PHPExcel_Cell_DataType::TYPE_ERROR:
  227. $this->_value = PHPExcel_Cell_DataType::checkErrorCode($pValue);
  228. break;
  229. default:
  230. throw new Exception('Invalid datatype: ' . $pDataType);
  231. break;
  232. }
  233. // set the datatype
  234. $this->_dataType = $pDataType;
  235. return $this->notifyCacheController();
  236. }
  237. /**
  238. * Get calculated cell value
  239. *
  240. * @return mixed
  241. */
  242. public function getCalculatedValue($resetLog=true)
  243. {
  244. // echo 'Cell '.$this->getCoordinate().' value is a '.$this->_dataType.' with a value of '.$this->getValue().'<br />';
  245. if ($this->_dataType == PHPExcel_Cell_DataType::TYPE_FORMULA) {
  246. try {
  247. // echo 'Cell value for '.$this->getCoordinate().' is a formula: Calculating value<br />';
  248. $result = PHPExcel_Calculation::getInstance()->calculateCellValue($this,$resetLog);
  249. // echo $this->getCoordinate().' calculation result is '.$result.'<br />';
  250. } catch ( Exception $ex ) {
  251. // echo 'Calculation Exception: '.$ex->getMessage().'<br />';
  252. $result = '#N/A';
  253. throw(new Exception($this->getParent()->getTitle().'!'.$this->getCoordinate().' -> '.$ex->getMessage()));
  254. }
  255. if ($result === '#Not Yet Implemented') {
  256. // echo 'Returning fallback value of '.$this->_calculatedValue.' for cell '.$this->getCoordinate().'<br />';
  257. return $this->_calculatedValue; // Fallback if calculation engine does not support the formula.
  258. }
  259. // echo 'Returning calculated value of '.$result.' for cell '.$this->getCoordinate().'<br />';
  260. return $result;
  261. }
  262. // if (is_null($this->_value)) {
  263. // echo 'Cell '.$this->getCoordinate().' has no value, formula or otherwise<br />';
  264. // return null;
  265. // }
  266. // echo 'Cell value for '.$this->getCoordinate().' is not a formula: Returning data value of '.$this->_value.'<br />';
  267. return $this->_value;
  268. }
  269. /**
  270. * Set calculated value (used for caching)
  271. *
  272. * @param mixed $pValue Value
  273. * @return PHPExcel_Cell
  274. */
  275. public function setCalculatedValue($pValue = null)
  276. {
  277. if (!is_null($pValue)) {
  278. $this->_calculatedValue = $pValue;
  279. }
  280. return $this->notifyCacheController();
  281. }
  282. /**
  283. * Get old calculated value (cached)
  284. *
  285. * @return mixed
  286. */
  287. public function getOldCalculatedValue()
  288. {
  289. return $this->_calculatedValue;
  290. }
  291. /**
  292. * Get cell data type
  293. *
  294. * @return string
  295. */
  296. public function getDataType()
  297. {
  298. return $this->_dataType;
  299. }
  300. /**
  301. * Set cell data type
  302. *
  303. * @param string $pDataType
  304. * @return PHPExcel_Cell
  305. */
  306. public function setDataType($pDataType = PHPExcel_Cell_DataType::TYPE_STRING)
  307. {
  308. if ($pDataType == PHPExcel_Cell_DataType::TYPE_STRING2)
  309. $pDataType = PHPExcel_Cell_DataType::TYPE_STRING;
  310. $this->_dataType = $pDataType;
  311. return $this->notifyCacheController();
  312. }
  313. /**
  314. * Has Data validation?
  315. *
  316. * @return boolean
  317. */
  318. public function hasDataValidation()
  319. {
  320. if (!isset($this->_parent)) {
  321. throw new Exception('Cannot check for data validation when cell is not bound to a worksheet');
  322. }
  323. return $this->_parent->dataValidationExists($this->getCoordinate());
  324. }
  325. /**
  326. * Get Data validation
  327. *
  328. * @return PHPExcel_Cell_DataValidation
  329. */
  330. public function getDataValidation()
  331. {
  332. if (!isset($this->_parent)) {
  333. throw new Exception('Cannot get data validation for cell that is not bound to a worksheet');
  334. }
  335. return $this->_parent->getDataValidation($this->getCoordinate());
  336. }
  337. /**
  338. * Set Data validation
  339. *
  340. * @param PHPExcel_Cell_DataValidation $pDataValidation
  341. * @throws Exception
  342. * @return PHPExcel_Cell
  343. */
  344. public function setDataValidation(PHPExcel_Cell_DataValidation $pDataValidation = null)
  345. {
  346. if (!isset($this->_parent)) {
  347. throw new Exception('Cannot set data validation for cell that is not bound to a worksheet');
  348. }
  349. $this->_parent->setDataValidation($this->getCoordinate(), $pDataValidation);
  350. return $this->notifyCacheController();
  351. }
  352. /**
  353. * Has Hyperlink
  354. *
  355. * @return boolean
  356. */
  357. public function hasHyperlink()
  358. {
  359. if (!isset($this->_parent)) {
  360. throw new Exception('Cannot check for hyperlink when cell is not bound to a worksheet');
  361. }
  362. return $this->_parent->hyperlinkExists($this->getCoordinate());
  363. }
  364. /**
  365. * Get Hyperlink
  366. *
  367. * @throws Exception
  368. * @return PHPExcel_Cell_Hyperlink
  369. */
  370. public function getHyperlink()
  371. {
  372. if (!isset($this->_parent)) {
  373. throw new Exception('Cannot get hyperlink for cell that is not bound to a worksheet');
  374. }
  375. return $this->_parent->getHyperlink($this->getCoordinate());
  376. }
  377. /**
  378. * Set Hyperlink
  379. *
  380. * @param PHPExcel_Cell_Hyperlink $pHyperlink
  381. * @throws Exception
  382. * @return PHPExcel_Cell
  383. */
  384. public function setHyperlink(PHPExcel_Cell_Hyperlink $pHyperlink = null)
  385. {
  386. if (!isset($this->_parent)) {
  387. throw new Exception('Cannot set hyperlink for cell that is not bound to a worksheet');
  388. }
  389. $this->_parent->setHyperlink($this->getCoordinate(), $pHyperlink);
  390. return $this->notifyCacheController();
  391. }
  392. /**
  393. * Get parent
  394. *
  395. * @return PHPExcel_Worksheet
  396. */
  397. public function getParent() {
  398. return $this->_parent;
  399. }
  400. /**
  401. * Re-bind parent
  402. *
  403. * @param PHPExcel_Worksheet $parent
  404. * @return PHPExcel_Cell
  405. */
  406. public function rebindParent(PHPExcel_Worksheet $parent) {
  407. $this->_parent = $parent;
  408. return $this->notifyCacheController();
  409. }
  410. /**
  411. * Is cell in a specific range?
  412. *
  413. * @param string $pRange Cell range (e.g. A1:A1)
  414. * @return boolean
  415. */
  416. public function isInRange($pRange = 'A1:A1')
  417. {
  418. list($rangeStart,$rangeEnd) = PHPExcel_Cell::rangeBoundaries($pRange);
  419. // Translate properties
  420. $myColumn = PHPExcel_Cell::columnIndexFromString($this->getColumn());
  421. $myRow = $this->getRow();
  422. // Verify if cell is in range
  423. return (($rangeStart[0] <= $myColumn) && ($rangeEnd[0] >= $myColumn) &&
  424. ($rangeStart[1] <= $myRow) && ($rangeEnd[1] >= $myRow)
  425. );
  426. }
  427. /**
  428. * Coordinate from string
  429. *
  430. * @param string $pCoordinateString
  431. * @return array Array containing column and row (indexes 0 and 1)
  432. * @throws Exception
  433. */
  434. public static function coordinateFromString($pCoordinateString = 'A1')
  435. {
  436. if (preg_match("/^([$]?[A-Z]{1,3})([$]?\d{1,7})$/", $pCoordinateString, $matches)) {
  437. return array($matches[1],$matches[2]);
  438. } elseif ((strpos($pCoordinateString,':') !== false) || (strpos($pCoordinateString,',') !== false)) {
  439. throw new Exception('Cell coordinate string can not be a range of cells.');
  440. } elseif ($pCoordinateString == '') {
  441. throw new Exception('Cell coordinate can not be zero-length string.');
  442. } else {
  443. throw new Exception('Invalid cell coordinate '.$pCoordinateString);
  444. }
  445. }
  446. /**
  447. * Make string row, column or cell coordinate absolute
  448. *
  449. * @param string $pCoordinateString e.g. 'A' or '1' or 'A1'
  450. * @return string Absolute coordinate e.g. '$A' or '$1' or '$A$1'
  451. * @throws Exception
  452. */
  453. public static function absoluteReference($pCoordinateString = 'A1')
  454. {
  455. if (strpos($pCoordinateString,':') === false && strpos($pCoordinateString,',') === false) {
  456. // Create absolute coordinate
  457. if (ctype_digit($pCoordinateString)) {
  458. return '$'.$pCoordinateString;
  459. } elseif (ctype_alpha($pCoordinateString)) {
  460. return '$'.strtoupper($pCoordinateString);
  461. }
  462. return self::absoluteCoordinate($pCoordinateString);
  463. } else {
  464. throw new Exception("Coordinate string should not be a cell range.");
  465. }
  466. }
  467. /**
  468. * Make string coordinate absolute
  469. *
  470. * @param string $pCoordinateString e.g. 'A1'
  471. * @return string Absolute coordinate e.g. '$A$1'
  472. * @throws Exception
  473. */
  474. public static function absoluteCoordinate($pCoordinateString = 'A1')
  475. {
  476. if (strpos($pCoordinateString,':') === false && strpos($pCoordinateString,',') === false) {
  477. // Create absolute coordinate
  478. list($column, $row) = PHPExcel_Cell::coordinateFromString($pCoordinateString);
  479. if ($column[0] == '$') $column = substr($column,1);
  480. if ($row[0] == '$') $row = substr($row,1);
  481. return '$' . $column . '$' . $row;
  482. } else {
  483. throw new Exception("Coordinate string should not be a cell range.");
  484. }
  485. }
  486. /**
  487. * Split range into coordinate strings
  488. *
  489. * @param string $pRange
  490. * @return array Array containg one or more arrays containing one or two coordinate strings
  491. */
  492. public static function splitRange($pRange = 'A1:A1')
  493. {
  494. $exploded = explode(',', $pRange);
  495. $counter = count($exploded);
  496. for ($i = 0; $i < $counter; ++$i) {
  497. $exploded[$i] = explode(':', $exploded[$i]);
  498. }
  499. return $exploded;
  500. }
  501. /**
  502. * Build range from coordinate strings
  503. *
  504. * @param array $pRange Array containg one or more arrays containing one or two coordinate strings
  505. * @return string String representation of $pRange
  506. * @throws Exception
  507. */
  508. public static function buildRange($pRange)
  509. {
  510. // Verify range
  511. if (!is_array($pRange) || count($pRange) == 0 || !is_array($pRange[0])) {
  512. throw new Exception('Range does not contain any information.');
  513. }
  514. // Build range
  515. $imploded = array();
  516. $counter = count($pRange);
  517. for ($i = 0; $i < $counter; ++$i) {
  518. $pRange[$i] = implode(':', $pRange[$i]);
  519. }
  520. $imploded = implode(',', $pRange);
  521. return $imploded;
  522. }
  523. /**
  524. * Calculate range boundaries
  525. *
  526. * @param string $pRange Cell range (e.g. A1:A1)
  527. * @return array Range coordinates (Start Cell, End Cell) where Start Cell and End Cell are arrays (Column Number, Row Number)
  528. */
  529. public static function rangeBoundaries($pRange = 'A1:A1')
  530. {
  531. // Uppercase coordinate
  532. $pRange = strtoupper($pRange);
  533. // Extract range
  534. if (strpos($pRange, ':') === false) {
  535. $rangeA = $rangeB = $pRange;
  536. } else {
  537. list($rangeA, $rangeB) = explode(':', $pRange);
  538. }
  539. // Calculate range outer borders
  540. $rangeStart = PHPExcel_Cell::coordinateFromString($rangeA);
  541. $rangeEnd = PHPExcel_Cell::coordinateFromString($rangeB);
  542. // Translate column into index
  543. $rangeStart[0] = PHPExcel_Cell::columnIndexFromString($rangeStart[0]);
  544. $rangeEnd[0] = PHPExcel_Cell::columnIndexFromString($rangeEnd[0]);
  545. return array($rangeStart, $rangeEnd);
  546. }
  547. /**
  548. * Calculate range dimension
  549. *
  550. * @param string $pRange Cell range (e.g. A1:A1)
  551. * @return array Range dimension (width, height)
  552. */
  553. public static function rangeDimension($pRange = 'A1:A1')
  554. {
  555. // Calculate range outer borders
  556. list($rangeStart,$rangeEnd) = PHPExcel_Cell::rangeBoundaries($pRange);
  557. return array( ($rangeEnd[0] - $rangeStart[0] + 1), ($rangeEnd[1] - $rangeStart[1] + 1) );
  558. }
  559. /**
  560. * Calculate range boundaries
  561. *
  562. * @param string $pRange Cell range (e.g. A1:A1)
  563. * @return array Range boundaries (staring Column, starting Row, Final Column, Final Row)
  564. */
  565. public static function getRangeBoundaries($pRange = 'A1:A1')
  566. {
  567. // Uppercase coordinate
  568. $pRange = strtoupper($pRange);
  569. // Extract range
  570. if (strpos($pRange, ':') === false) {
  571. $rangeA = $rangeB = $pRange;
  572. } else {
  573. list($rangeA, $rangeB) = explode(':', $pRange);
  574. }
  575. return array( self::coordinateFromString($rangeA), self::coordinateFromString($rangeB));
  576. }
  577. /**
  578. * Column index from string
  579. *
  580. * @param string $pString
  581. * @return int Column index (base 1 !!!)
  582. * @throws Exception
  583. */
  584. public static function columnIndexFromString($pString = 'A')
  585. {
  586. // It's surprising how costly the strtoupper() and ord() calls actually are, so we use a lookup array rather than use ord()
  587. // and make it case insensitive to get rid of the strtoupper() as well. Because it's a static, there's no significant
  588. // memory overhead either
  589. static $_columnLookup = array(
  590. '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,
  591. '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,
  592. '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,
  593. '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
  594. );
  595. // We also use the language construct isset() rather than the more costly strlen() function to match the length of $pString
  596. // for improved performance
  597. if (isset($pString{0})) {
  598. if (!isset($pString{1})) {
  599. return $_columnLookup[$pString];
  600. } elseif(!isset($pString{2})) {
  601. return $_columnLookup[$pString{0}] * 26 + $_columnLookup[$pString{1}];
  602. } elseif(!isset($pString{3})) {
  603. return $_columnLookup[$pString{0}] * 676 + $_columnLookup[$pString{1}] * 26 + $_columnLookup[$pString{2}];
  604. }
  605. }
  606. throw new Exception("Column string index can not be " . ((isset($pString{0})) ? "longer than 3 characters" : "empty") . ".");
  607. }
  608. /**
  609. * String from columnindex
  610. *
  611. * @param int $pColumnIndex Column index (base 0 !!!)
  612. * @return string
  613. */
  614. public static function stringFromColumnIndex($pColumnIndex = 0)
  615. {
  616. // Determine column string
  617. if ($pColumnIndex < 26) {
  618. return chr(65 + $pColumnIndex);
  619. } elseif ($pColumnIndex < 702) {
  620. return chr(64 + ($pColumnIndex / 26)).chr(65 + $pColumnIndex % 26);
  621. }
  622. return chr(64 + (($pColumnIndex - 26) / 676)).chr(65 + ((($pColumnIndex - 26) % 676) / 26)).chr(65 + $pColumnIndex % 26);
  623. }
  624. /**
  625. * Extract all cell references in range
  626. *
  627. * @param string $pRange Range (e.g. A1 or A1:A10 or A1:A10 A100:A1000)
  628. * @return array Array containing single cell references
  629. */
  630. public static function extractAllCellReferencesInRange($pRange = 'A1') {
  631. // Returnvalue
  632. $returnValue = array();
  633. // Explode spaces
  634. $cellBlocks = explode(' ', str_replace('$', '', strtoupper($pRange)));
  635. foreach ($cellBlocks as $cellBlock) {
  636. // Single cell?
  637. if (strpos($cellBlock,':') === false && strpos($cellBlock,',') === false) {
  638. $returnValue[] = $cellBlock;
  639. continue;
  640. }
  641. // Range...
  642. $ranges = PHPExcel_Cell::splitRange($cellBlock);
  643. foreach($ranges as $range) {
  644. // Single cell?
  645. if (!isset($range[1])) {
  646. $returnValue[] = $range[0];
  647. continue;
  648. }
  649. // Range...
  650. list($rangeStart, $rangeEnd) = $range;
  651. list($startCol, $startRow) = sscanf($rangeStart,'%[A-Z]%d');
  652. list($endCol, $endRow) = sscanf($rangeEnd,'%[A-Z]%d');
  653. $endCol++;
  654. // Current data
  655. $currentCol = $startCol;
  656. $currentRow = $startRow;
  657. // Loop cells
  658. while ($currentCol != $endCol) {
  659. while ($currentRow <= $endRow) {
  660. $returnValue[] = $currentCol.$currentRow;
  661. ++$currentRow;
  662. }
  663. ++$currentCol;
  664. $currentRow = $startRow;
  665. }
  666. }
  667. }
  668. // Return value
  669. return $returnValue;
  670. }
  671. /**
  672. * Compare 2 cells
  673. *
  674. * @param PHPExcel_Cell $a Cell a
  675. * @param PHPExcel_Cell $a Cell b
  676. * @return int Result of comparison (always -1 or 1, never zero!)
  677. */
  678. public static function compareCells(PHPExcel_Cell $a, PHPExcel_Cell $b)
  679. {
  680. if ($a->_row < $b->_row) {
  681. return -1;
  682. } elseif ($a->_row > $b->_row) {
  683. return 1;
  684. } elseif (PHPExcel_Cell::columnIndexFromString($a->_column) < PHPExcel_Cell::columnIndexFromString($b->_column)) {
  685. return -1;
  686. } else {
  687. return 1;
  688. }
  689. }
  690. /**
  691. * Get value binder to use
  692. *
  693. * @return PHPExcel_Cell_IValueBinder
  694. */
  695. public static function getValueBinder() {
  696. if (is_null(self::$_valueBinder)) {
  697. self::$_valueBinder = new PHPExcel_Cell_DefaultValueBinder();
  698. }
  699. return self::$_valueBinder;
  700. }
  701. /**
  702. * Set value binder to use
  703. *
  704. * @param PHPExcel_Cell_IValueBinder $binder
  705. * @throws Exception
  706. */
  707. public static function setValueBinder(PHPExcel_Cell_IValueBinder $binder = null) {
  708. if (is_null($binder)) {
  709. throw new Exception("A PHPExcel_Cell_IValueBinder is required for PHPExcel to function correctly.");
  710. }
  711. self::$_valueBinder = $binder;
  712. }
  713. /**
  714. * Implement PHP __clone to create a deep clone, not just a shallow copy.
  715. */
  716. public function __clone() {
  717. $vars = get_object_vars($this);
  718. foreach ($vars as $key => $value) {
  719. if ((is_object($value)) && ($key != '_parent')) {
  720. $this->$key = clone $value;
  721. } else {
  722. $this->$key = $value;
  723. }
  724. }
  725. }
  726. /**
  727. * Get index to cellXf
  728. *
  729. * @return int
  730. */
  731. public function getXfIndex()
  732. {
  733. return $this->_xfIndex;
  734. }
  735. /**
  736. * Set index to cellXf
  737. *
  738. * @param int $pValue
  739. * @return PHPExcel_Cell
  740. */
  741. public function setXfIndex($pValue = 0)
  742. {
  743. $this->_xfIndex = $pValue;
  744. return $this->notifyCacheController();
  745. }
  746. public function setFormulaAttributes($pAttributes)
  747. {
  748. $this->_formulaAttributes = $pAttributes;
  749. return $this;
  750. }
  751. public function getFormulaAttributes()
  752. {
  753. return $this->_formulaAttributes;
  754. }
  755. }