107 $this->_parent->getCellCacheController()->updateCacheData($this);
112 $this->_parent = null;
116 $this->_parent = $parent;
133 $this->_column = strtoupper($pColumn);
137 $this->_value = $pValue;
140 $this->_parent = $pSheet;
143 if ($pDataType !== null) {
146 $this->_dataType = $pDataType;
148 if (!self::getValueBinder()->bindValue($this, $pValue)) {
149 throw new Exception(
"Value could not be bound to cell.");
205 $this->_parent->getParent()->getCellXfByIndex($this->
getXfIndex())->getNumberFormat()->getFormatCode()
219 if (!self::getValueBinder()->bindValue($this, $pValue)) {
220 throw new Exception(
"Value could not be bound to cell.");
236 switch ($pDataType) {
246 $this->_value = (float)$pValue;
250 $this->_value = (string)$pValue;
254 $this->_value = (bool)$pValue;
262 throw new Exception(
'Invalid datatype: ' . $pDataType);
267 $this->_dataType = $pDataType;
291 if ($result ===
'#Not Yet Implemented') {
315 if (!is_null($pValue)) {
316 $this->_calculatedValue = $pValue;
353 $this->_dataType = $pDataType;
365 if (!isset($this->_parent)) {
366 throw new Exception(
'Cannot check for data validation when cell is not bound to a worksheet');
369 return $this->_parent->dataValidationExists($this->
getCoordinate());
379 if (!isset($this->_parent)) {
380 throw new Exception(
'Cannot get data validation for cell that is not bound to a worksheet');
383 return $this->_parent->getDataValidation($this->
getCoordinate());
395 if (!isset($this->_parent)) {
396 throw new Exception(
'Cannot set data validation for cell that is not bound to a worksheet');
399 $this->_parent->setDataValidation($this->
getCoordinate(), $pDataValidation);
411 if (!isset($this->_parent)) {
412 throw new Exception(
'Cannot check for hyperlink when cell is not bound to a worksheet');
415 return $this->_parent->hyperlinkExists($this->
getCoordinate());
426 if (!isset($this->_parent)) {
427 throw new Exception(
'Cannot get hyperlink for cell that is not bound to a worksheet');
442 if (!isset($this->_parent)) {
443 throw new Exception(
'Cannot set hyperlink for cell that is not bound to a worksheet');
446 $this->_parent->setHyperlink($this->
getCoordinate(), $pHyperlink);
467 $this->_parent = $parent;
487 return (($rangeStart[0] <= $myColumn) && ($rangeEnd[0] >= $myColumn) &&
488 ($rangeStart[1] <= $myRow) && ($rangeEnd[1] >= $myRow)
501 if (preg_match(
"/^([$]?[A-Z]{1,3})([$]?\d{1,7})$/", $pCoordinateString, $matches)) {
502 return array($matches[1],$matches[2]);
503 } elseif ((strpos($pCoordinateString,
':') !==
false) || (strpos($pCoordinateString,
',') !==
false)) {
504 throw new Exception(
'Cell coordinate string can not be a range of cells.');
505 } elseif ($pCoordinateString ==
'') {
506 throw new Exception(
'Cell coordinate can not be zero-length string.');
508 throw new Exception(
'Invalid cell coordinate '.$pCoordinateString);
521 if (strpos($pCoordinateString,
':') ===
false && strpos($pCoordinateString,
',') ===
false) {
523 if (ctype_digit($pCoordinateString)) {
524 return '$'.$pCoordinateString;
525 } elseif (ctype_alpha($pCoordinateString)) {
526 return '$'.strtoupper($pCoordinateString);
530 throw new Exception(
"Coordinate string should not be a cell range.");
543 if (strpos($pCoordinateString,
':') ===
false && strpos($pCoordinateString,
',') ===
false) {
546 if ($column[0] ==
'$') $column = substr($column,1);
548 return '$' . $column .
'$' .
$row;
550 throw new Exception(
"Coordinate string should not be a cell range.");
562 $exploded = explode(
',', $pRange);
563 $counter = count($exploded);
564 for ($i = 0; $i < $counter; ++$i) {
565 $exploded[$i] = explode(
':', $exploded[$i]);
580 if (!is_array($pRange) || count($pRange) == 0 || !is_array($pRange[0])) {
581 throw new Exception(
'Range does not contain any information.');
586 $counter = count($pRange);
587 for ($i = 0; $i < $counter; ++$i) {
588 $pRange[$i] = implode(
':', $pRange[$i]);
590 $imploded = implode(
',', $pRange);
604 $pRange = strtoupper($pRange);
607 if (strpos($pRange,
':') ===
false) {
608 $rangeA = $rangeB = $pRange;
610 list($rangeA, $rangeB) = explode(
':', $pRange);
621 return array($rangeStart, $rangeEnd);
635 return array( ($rangeEnd[0] - $rangeStart[0] + 1), ($rangeEnd[1] - $rangeStart[1] + 1) );
647 $pRange = strtoupper($pRange);
650 if (strpos($pRange,
':') ===
false) {
651 $rangeA = $rangeB = $pRange;
653 list($rangeA, $rangeB) = explode(
':', $pRange);
656 return array( self::coordinateFromString($rangeA), self::coordinateFromString($rangeB));
671 static $_columnLookup = array(
672 '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,
673 '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,
674 '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,
675 '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
680 if (isset($pString{0})) {
681 if (!isset($pString{1})) {
682 return $_columnLookup[$pString];
683 } elseif(!isset($pString{2})) {
684 return $_columnLookup[$pString{0}] * 26 + $_columnLookup[$pString{1}];
685 } elseif(!isset($pString{3})) {
686 return $_columnLookup[$pString{0}] * 676 + $_columnLookup[$pString{1}] * 26 + $_columnLookup[$pString{2}];
689 throw new Exception(
"Column string index can not be " . ((isset($pString{0})) ?
"longer than 3 characters" :
"empty") .
".");
701 if ($pColumnIndex < 26) {
702 return chr(65 + $pColumnIndex);
703 } elseif ($pColumnIndex < 702) {
704 return chr(64 + ($pColumnIndex / 26)).chr(65 + $pColumnIndex % 26);
706 return chr(64 + (($pColumnIndex - 26) / 676)).chr(65 + ((($pColumnIndex - 26) % 676) / 26)).chr(65 + $pColumnIndex % 26);
717 $returnValue = array();
720 $cellBlocks = explode(
' ', str_replace(
'$',
'', strtoupper($pRange)));
721 foreach ($cellBlocks as $cellBlock) {
723 if (strpos($cellBlock,
':') ===
false && strpos($cellBlock,
',') ===
false) {
724 $returnValue[] = $cellBlock;
730 foreach($ranges as $range) {
732 if (!isset($range[1])) {
733 $returnValue[] = $range[0];
738 list($rangeStart, $rangeEnd) = $range;
739 list($startCol, $startRow) = sscanf($rangeStart,
'%[A-Z]%d');
740 list($endCol, $endRow) = sscanf($rangeEnd,
'%[A-Z]%d');
744 $currentCol = $startCol;
745 $currentRow = $startRow;
748 while ($currentCol != $endCol) {
749 while ($currentRow <= $endRow) {
750 $returnValue[] = $currentCol.$currentRow;
754 $currentRow = $startRow;
772 if ($a->_row < $b->_row) {
774 } elseif ($a->_row > $b->_row) {
789 if (is_null(self::$_valueBinder)) {
803 if (is_null($binder)) {
804 throw new Exception(
"A PHPExcel_Cell_IValueBinder is required for PHPExcel to function correctly.");
807 self::$_valueBinder = $binder;
814 $vars = get_object_vars($this);
815 foreach ($vars as $key => $value) {
816 if ((is_object($value)) && ($key !=
'_parent')) {
817 $this->$key = clone $value;
819 $this->$key = $value;
842 $this->_xfIndex = $pValue;
850 $this->_formulaAttributes = $pAttributes;