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

Documentation generated on Mon, 05 Jan 2009 20:38:07 +0100 by phpDocumentor 1.4.1