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

Documentation generated on Sun, 27 Feb 2011 16:28:58 -0800 by phpDocumentor 1.4.3