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

Documentation generated on Mon, 10 Aug 2009 08:06:39 +0200 by phpDocumentor 1.4.1