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 - 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
  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.6.7, 2009-04-22
  26.  */
  27.  
  28.  
  29. /** PHPExcel */
  30. require_once 'PHPExcel.php';
  31.  
  32. /** PHPExcel_Worksheet */
  33. require_once 'PHPExcel/Worksheet.php';
  34.  
  35. /** PHPExcel_ReferenceHelper */
  36. require_once 'PHPExcel/ReferenceHelper.php';
  37.  
  38.  
  39. /**
  40.  * PHPExcel_NamedRange
  41.  *
  42.  * @category   PHPExcel
  43.  * @package    PHPExcel
  44.  * @copyright  Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
  45.  */
  46. {
  47.     /**
  48.      * Range name
  49.      *
  50.      * @var string 
  51.      */
  52.     private $_name;
  53.     
  54.     /**
  55.      * Worksheet on which the named range can be resolved
  56.      *
  57.      * @var PHPExcel_Worksheet 
  58.      */
  59.     private $_worksheet;
  60.     
  61.     /**
  62.      * Range of the referenced cells
  63.      *
  64.      * @var string 
  65.      */
  66.     private $_range;
  67.     
  68.     /**
  69.      * Is the named range local? (i.e. can only be used on $this->_worksheet)
  70.      *
  71.      * @var bool 
  72.      */
  73.     private $_localOnly;
  74.     
  75.     /**
  76.      * Create a new NamedRange
  77.      *
  78.      * @param string $pName 
  79.      * @param PHPExcel_Worksheet $pWorksheet 
  80.      * @param string $pRange 
  81.      * @param bool $pLocalOnly 
  82.      */
  83.     public function __construct($pName nullPHPExcel_Worksheet $pWorksheet$pRange 'A1'$pLocalOnly false)
  84.     {
  85.         // Validate data
  86.         if (is_null($pName|| is_null($pWorksheet)|| is_null($pRange)) {
  87.             throw new Exception('Parameters can not be null.');
  88.         }
  89.         
  90.         // Set local members
  91.         $this->_name         = $pName;
  92.         $this->_worksheet     = $pWorksheet;
  93.         $this->_range         = $pRange;
  94.         $this->_localOnly     = $pLocalOnly;
  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.      */
  111.     public function setName($value null{
  112.         if (!is_null($value)) {
  113.             // Old title
  114.             $oldTitle $this->_name;
  115.             
  116.             // Re-attach
  117.             if (!is_null($this->_worksheet)) {
  118.                 $this->_worksheet->getParent()->removeNamedRange($this->_name);
  119.             }
  120.             $this->_name = $value;
  121.             if (!is_null($this->_worksheet)) {
  122.                 $this->_worksheet->getParent()->addNamedRange($this);
  123.             }
  124.             
  125.             // New title
  126.             $newTitle $this->_name;
  127.             PHPExcel_ReferenceHelper::getInstance()->updateNamedFormulas($this->_worksheet->getParent()$oldTitle$newTitle);
  128.         }
  129.     }
  130.     
  131.     /**
  132.      * Get worksheet
  133.      *
  134.      * @return PHPExcel_Worksheet 
  135.      */
  136.     public function getWorksheet({
  137.         return $this->_worksheet;
  138.     }
  139.     
  140.     /**
  141.      * Set worksheet
  142.      *
  143.      * @param PHPExcel_Worksheet $value 
  144.      */
  145.     public function setWorksheet(PHPExcel_Worksheet $value null{
  146.         if (!is_null($value)) {
  147.             $this->_worksheet = $value;
  148.         }
  149.     }
  150.     
  151.     /**
  152.      * Get range
  153.      *
  154.      * @return string 
  155.      */
  156.     public function getRange({
  157.         return $this->_range;
  158.     }
  159.     
  160.     /**
  161.      * Set range
  162.      *
  163.      * @param string $value 
  164.      */
  165.     public function setRange($value null{
  166.         if (!is_null($value)) {
  167.             $this->_range = $value;
  168.         }
  169.     }
  170.     
  171.     /**
  172.      * Get localOnly
  173.      *
  174.      * @return bool 
  175.      */
  176.     public function getLocalOnly({
  177.         return $this->_localOnly;
  178.     }
  179.     
  180.     /**
  181.      * Set localOnly
  182.      *
  183.      * @param bool $value 
  184.      */
  185.     public function setLocalOnly($value false{
  186.         $this->_localOnly = $value;
  187.     }
  188.     
  189.     /**
  190.      * Resolve a named range to a regular cell range
  191.      *
  192.      * @param string $pNamedRange Named range
  193.      * @param PHPExcel_Worksheet $pSheet Worksheet
  194.      * @return PHPExcel_NamedRange 
  195.      */
  196.     public static function resolveRange($pNamedRange ''PHPExcel_Worksheet $pSheet{
  197.         return $pSheet->getParent()->getNamedRange($pNamedRange);
  198.     }
  199.         
  200.     /**
  201.      * Implement PHP __clone to create a deep clone, not just a shallow copy.
  202.      */
  203.     public function __clone({
  204.         $vars get_object_vars($this);
  205.         foreach ($vars as $key => $value{
  206.             if (is_object($value)) {
  207.                 $this->$key clone $value;
  208.             else {
  209.                 $this->$key $value;
  210.             }
  211.         }
  212.     }
  213. }

Documentation generated on Wed, 22 Apr 2009 09:00:45 +0200 by phpDocumentor 1.4.1