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

Source for file NamedRange.php

Documentation is available at NamedRange.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
  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_NamedRange
  31.  *
  32.  * @category   PHPExcel
  33.  * @package    PHPExcel
  34.  * @copyright  Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
  35.  */
  36. {
  37.     /**
  38.      * Range name
  39.      *
  40.      * @var string 
  41.      */
  42.     private $_name;
  43.  
  44.     /**
  45.      * Worksheet on which the named range can be resolved
  46.      *
  47.      * @var PHPExcel_Worksheet 
  48.      */
  49.     private $_worksheet;
  50.  
  51.     /**
  52.      * Range of the referenced cells
  53.      *
  54.      * @var string 
  55.      */
  56.     private $_range;
  57.  
  58.     /**
  59.      * Is the named range local? (i.e. can only be used on $this->_worksheet)
  60.      *
  61.      * @var bool 
  62.      */
  63.     private $_localOnly;
  64.  
  65.     /**
  66.      * Scope
  67.      *
  68.      * @var PHPExcel_Worksheet 
  69.      */
  70.     private $_scope;
  71.  
  72.     /**
  73.      * Create a new NamedRange
  74.      *
  75.      * @param string $pName 
  76.      * @param PHPExcel_Worksheet $pWorksheet 
  77.      * @param string $pRange 
  78.      * @param bool $pLocalOnly 
  79.      * @param PHPExcel_Worksheet|null$pScope    Scope. Only applies when $pLocalOnly = true. Null for global scope.
  80.      */
  81.     public function __construct($pName nullPHPExcel_Worksheet $pWorksheet$pRange 'A1'$pLocalOnly false$pScope null)
  82.     {
  83.         // Validate data
  84.         if (is_null($pName|| is_null($pWorksheet)|| is_null($pRange)) {
  85.             throw new Exception('Parameters can not be null.');
  86.         }
  87.  
  88.         // Set local members
  89.         $this->_name         $pName;
  90.         $this->_worksheet     $pWorksheet;
  91.         $this->_range         $pRange;
  92.         $this->_localOnly     $pLocalOnly;
  93.         $this->_scope         ($pLocalOnly == true?
  94.                                 (($pScope == null$pWorksheet $pScopenull;
  95.     }
  96.  
  97.     /**
  98.      * Get name
  99.      *
  100.      * @return string 
  101.      */
  102.     public function getName({
  103.         return $this->_name;
  104.     }
  105.  
  106.     /**
  107.      * Set name
  108.      *
  109.      * @param string $value 
  110.      * @return PHPExcel_NamedRange 
  111.      */
  112.     public function setName($value null{
  113.         if (!is_null($value)) {
  114.             // Old title
  115.             $oldTitle $this->_name;
  116.  
  117.             // Re-attach
  118.             if (!is_null($this->_worksheet)) {
  119.                 $this->_worksheet->getParent()->removeNamedRange($this->_name,$this->_worksheet);
  120.             }
  121.             $this->_name $value;
  122.  
  123.             if (!is_null($this->_worksheet)) {
  124.                 $this->_worksheet->getParent()->addNamedRange($this);
  125.             }
  126.  
  127.             // New title
  128.             $newTitle $this->_name;
  129.             PHPExcel_ReferenceHelper::getInstance()->updateNamedFormulas($this->_worksheet->getParent()$oldTitle$newTitle);
  130.         }
  131.         return $this;
  132.     }
  133.  
  134.     /**
  135.      * Get worksheet
  136.      *
  137.      * @return PHPExcel_Worksheet 
  138.      */
  139.     public function getWorksheet({
  140.         return $this->_worksheet;
  141.     }
  142.  
  143.     /**
  144.      * Set worksheet
  145.      *
  146.      * @param PHPExcel_Worksheet $value 
  147.      * @return PHPExcel_NamedRange 
  148.      */
  149.     public function setWorksheet(PHPExcel_Worksheet $value null{
  150.         if (!is_null($value)) {
  151.             $this->_worksheet $value;
  152.         }
  153.         return $this;
  154.     }
  155.  
  156.     /**
  157.      * Get range
  158.      *
  159.      * @return string 
  160.      */
  161.     public function getRange({
  162.         return $this->_range;
  163.     }
  164.  
  165.     /**
  166.      * Set range
  167.      *
  168.      * @param string $value 
  169.      * @return PHPExcel_NamedRange 
  170.      */
  171.     public function setRange($value null{
  172.         if (!is_null($value)) {
  173.             $this->_range $value;
  174.         }
  175.         return $this;
  176.     }
  177.  
  178.     /**
  179.      * Get localOnly
  180.      *
  181.      * @return bool 
  182.      */
  183.     public function getLocalOnly({
  184.         return $this->_localOnly;
  185.     }
  186.  
  187.     /**
  188.      * Set localOnly
  189.      *
  190.      * @param bool $value 
  191.      * @return PHPExcel_NamedRange 
  192.      */
  193.     public function setLocalOnly($value false{
  194.         $this->_localOnly $value;
  195.         $this->_scope $value $this->_worksheet null;
  196.         return $this;
  197.     }
  198.  
  199.     /**
  200.      * Get scope
  201.      *
  202.      * @return PHPExcel_Worksheet|null
  203.      */
  204.     public function getScope({
  205.         return $this->_scope;
  206.     }
  207.  
  208.     /**
  209.      * Set scope
  210.      *
  211.      * @param PHPExcel_Worksheet|null$value 
  212.      * @return PHPExcel_NamedRange 
  213.      */
  214.     public function setScope(PHPExcel_Worksheet $value null{
  215.         $this->_scope $value;
  216.         $this->_localOnly ($value == nullfalse true;
  217.         return $this;
  218.     }
  219.  
  220.     /**
  221.      * Resolve a named range to a regular cell range
  222.      *
  223.      * @param string $pNamedRange Named range
  224.      * @param PHPExcel_Worksheet|null$pSheet Scope. Use null for global scope
  225.      * @return PHPExcel_NamedRange 
  226.      */
  227.     public static function resolveRange($pNamedRange ''PHPExcel_Worksheet $pSheet{
  228.         return $pSheet->getParent()->getNamedRange($pNamedRange$pSheet);
  229.     }
  230.  
  231.     /**
  232.      * Implement PHP __clone to create a deep clone, not just a shallow copy.
  233.      */
  234.     public function __clone({
  235.         $vars get_object_vars($this);
  236.         foreach ($vars as $key => $value{
  237.             if (is_object($value)) {
  238.                 $this->$key clone $value;
  239.             else {
  240.                 $this->$key $value;
  241.             }
  242.         }
  243.     }
  244. }

Documentation generated on Sun, 27 Feb 2011 16:32:49 -0800 by phpDocumentor 1.4.3