PageRenderTime 44ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 1ms

/add-ons/PHPExcel/PHPExcel/Cell.php

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