30 if (!defined(
'PHPEXCEL_ROOT')) {
34 define(
'PHPEXCEL_ROOT', dirname(__FILE__) .
'/../');
38 require_once PHPEXCEL_ROOT .
'PHPExcel/Cell/DataType.php';
41 require_once PHPEXCEL_ROOT .
'PHPExcel/Cell/DataValidation.php';
44 require_once PHPEXCEL_ROOT .
'PHPExcel/Cell/Hyperlink.php';
47 require_once PHPEXCEL_ROOT .
'PHPExcel/Worksheet.php';
50 require_once PHPEXCEL_ROOT .
'PHPExcel/Calculation.php';
53 require_once PHPEXCEL_ROOT .
'PHPExcel/Cell/IValueBinder.php';
56 require_once PHPEXCEL_ROOT .
'PHPExcel/Cell/DefaultValueBinder.php';
59 require_once PHPEXCEL_ROOT .
'PHPExcel/Shared/String.php';
140 if (is_null(self::$_valueBinder)) {
145 $this->_column = strtoupper($pColumn);
149 $this->_value = $pValue;
152 $this->_parent = $pSheet;
155 if (!is_null($pDataType)) {
156 $this->_dataType = $pDataType;
158 if (!self::getValueBinder()->bindValue($this, $pValue)) {
159 throw new Exception(
"Value could not be bound to cell.");
174 return strtoupper($this->_column);
217 if (!self::getValueBinder()->bindValue($this, $pValue)) {
218 throw new Exception(
"Value could not be bound to cell.");
239 $pValue = str_replace(array(
"\r\n",
"\r"),
"\n", $pValue);
242 $this->_value = $pValue;
243 $this->_dataType = $pDataType;
264 if ((is_string(
$result)) && (
$result ==
'#Not Yet Implemented')) {
273 if (is_null($this->_value)) {
293 if (!is_null($pValue)) {
294 $this->_calculatedValue = $pValue;
327 $this->_dataType = $pDataType;
338 if (!isset($this->_parent)) {
339 throw new Exception(
'Cannot check for data validation when cell is not bound to a worksheet');
342 return $this->_parent->dataValidationExists($this->
getCoordinate());
352 if (!isset($this->_parent)) {
353 throw new Exception(
'Cannot get data validation for cell that is not bound to a worksheet');
356 $dataValidation = $this->_parent->getDataValidation($this->
getCoordinate());
357 return $dataValidation;
369 if (!isset($this->_parent)) {
370 throw new Exception(
'Cannot set data validation for cell that is not bound to a worksheet');
373 $this->_parent->setDataValidation($this->
getCoordinate(), $pDataValidation);
384 if (!isset($this->_parent)) {
385 throw new Exception(
'Cannot check for hyperlink when cell is not bound to a worksheet');
388 return $this->_parent->hyperlinkExists($this->
getCoordinate());
399 if (!isset($this->_parent)) {
400 throw new Exception(
'Cannot get hyperlink for cell that is not bound to a worksheet');
403 $hyperlink = $this->_parent->getHyperlink($this->
getCoordinate());
416 if (!isset($this->_parent)) {
417 throw new Exception(
'Cannot set hyperlink for cell that is not bound to a worksheet');
420 $this->_parent->setHyperlink($this->
getCoordinate(), $pHyperlink);
440 $this->_parent = $parent;
453 $pRange = strtoupper($pRange);
458 if (strpos($pRange,
':') ===
false) {
462 list($rangeA, $rangeB) = explode(
':', $pRange);
479 ($rangeStart[0] <= $myColumn && $rangeEnd[0] >= $myColumn) &&
480 ($rangeStart[1] <= $myRow && $rangeEnd[1] >= $myRow)
493 if (strpos($pCoordinateString,
':') !==
false) {
494 throw new Exception(
'Cell coordinate string can not be a range of cells.');
495 }
else if ($pCoordinateString ==
'') {
496 throw new Exception(
'Cell coordinate can not be zero-length string.');
505 if (preg_match(
"/([$]?[A-Z]+)([$]?\d+)/", $pCoordinateString, $matches)) {
506 list(, $column,
$row) = $matches;
510 return array($column,
$row);
523 if (strpos($pCoordinateString,
':') ===
false && strpos($pCoordinateString,
',') ===
false) {
529 $returnValue =
'$' . $column .
'$' .
$row;
534 throw new Exception(
"Coordinate string should not be a cell range.");
546 $exploded = explode(
',', $pRange);
547 for ($i = 0; $i < count($exploded); ++$i) {
548 $exploded[$i] = explode(
':', $exploded[$i]);
563 if (!is_array($pRange) || count($pRange) == 0 || !is_array($pRange[0])) {
564 throw new Exception(
'Range does not contain any information.');
569 for ($i = 0; $i < count($pRange); ++$i) {
570 $pRange[$i] = implode(
':', $pRange[$i]);
572 $imploded = implode(
',', $pRange);
586 $pRange = strtoupper($pRange);
591 if (strpos($pRange,
':') ===
false) {
595 list($rangeA, $rangeB) = explode(
':', $pRange);
606 return array( ($rangeEnd[0] - $rangeStart[0] + 1), ($rangeEnd[1] - $rangeStart[1] + 1) );
619 $pString = strtoupper($pString);
621 $strLen = strlen($pString);
624 return (ord($pString{0}) - 64);
626 return $result = ((1 + (ord($pString{0}) - 65)) * 26) + (ord($pString{1}) - 64);
628 return ((1 + (ord($pString{0}) - 65)) * 676) + ((1 + (ord($pString{1}) - 65)) * 26) + (ord($pString{2}) - 64);
630 throw new Exception(
"Column string index can not be " . ($strLen != 0 ?
"longer than 3 characters" :
"empty") .
".");
643 if ($pColumnIndex < 26) {
644 return chr(65 + $pColumnIndex);
657 $returnValue = array();
660 $aExplodeSpaces = explode(
' ', str_replace(
'$',
'', strtoupper($pRange)));
661 foreach ($aExplodeSpaces as $explodedSpaces) {
663 if (strpos($explodedSpaces,
':') ===
false && strpos($explodedSpaces,
',') ===
false) {
668 if (strlen($col) <= 2) {
669 $returnValue[] = $explodedSpaces;
677 for ($i = 0; $i < count($range); ++$i) {
679 if (count($range[$i]) == 1) {
684 if (strlen($col) <= 2) {
685 $returnValue[] = $explodedSpaces;
690 $rangeStart = $rangeEnd =
'';
691 $startingCol = $startingRow = $endingCol = $endingRow = 0;
693 list($rangeStart, $rangeEnd) = $range[$i];
702 $currentCol = --$startingCol;
703 $currentRow = $startingRow;
706 while ($currentCol < $endingCol) {
708 while ($currentRow <= $endingRow) {
709 $returnValue[] = $loopColumn.$currentRow;
713 $currentRow = $startingRow;
731 if ($a->_row < $b->_row) {
733 }
elseif ($a->_row > $b->_row) {
758 if (is_null($binder)) {
759 throw new Exception(
"A PHPExcel_Cell_IValueBinder is required for PHPExcel to function correctly.");
762 self::$_valueBinder = $binder;
769 $vars = get_object_vars($this);
770 foreach ($vars as
$key => $value) {
771 if (is_object($value)) {
772 $this->
$key = clone $value;
774 $this->
$key = $value;
797 $this->_xfIndex = $pValue;