PHPExcel_Cell
[ class tree: PHPExcel_Cell ] [ index: PHPExcel_Cell ] [ all elements ]

Source for file Cell.php

Documentation is available at Cell.php

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

Documentation generated on Mon, 10 Aug 2009 08:02:36 +0200 by phpDocumentor 1.4.1