ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
NamedRange.php
Go to the documentation of this file.
1 <?php
30 if (!defined('PHPEXCEL_ROOT')) {
34  define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../');
35 }
36 
38 require_once PHPEXCEL_ROOT . 'PHPExcel.php';
39 
41 require_once PHPEXCEL_ROOT . 'PHPExcel/Worksheet.php';
42 
44 require_once PHPEXCEL_ROOT . 'PHPExcel/ReferenceHelper.php';
45 
46 
55 {
61  private $_name;
62 
68  private $_worksheet;
69 
75  private $_range;
76 
82  private $_localOnly;
83 
92  public function __construct($pName = null, PHPExcel_Worksheet $pWorksheet, $pRange = 'A1', $pLocalOnly = false)
93  {
94  // Validate data
95  if (is_null($pName) || is_null($pWorksheet)|| is_null($pRange)) {
96  throw new Exception('Parameters can not be null.');
97  }
98 
99  // Set local members
100  $this->_name = $pName;
101  $this->_worksheet = $pWorksheet;
102  $this->_range = $pRange;
103  $this->_localOnly = $pLocalOnly;
104  }
105 
111  public function getName() {
112  return $this->_name;
113  }
114 
121  public function setName($value = null) {
122  if (!is_null($value)) {
123  // Old title
124  $oldTitle = $this->_name;
125 
126  // Re-attach
127  if (!is_null($this->_worksheet)) {
128  $this->_worksheet->getParent()->removeNamedRange($this->_name,$this->_worksheet);
129  }
130  $this->_name = $value;
131 
132  if (!is_null($this->_worksheet)) {
133  $this->_worksheet->getParent()->addNamedRange($this);
134  }
135 
136  // New title
137  $newTitle = $this->_name;
138  PHPExcel_ReferenceHelper::getInstance()->updateNamedFormulas($this->_worksheet->getParent(), $oldTitle, $newTitle);
139  }
140  return $this;
141  }
142 
148  public function getWorksheet() {
149  return $this->_worksheet;
150  }
151 
158  public function setWorksheet(PHPExcel_Worksheet $value = null) {
159  if (!is_null($value)) {
160  $this->_worksheet = $value;
161  }
162  return $this;
163  }
164 
170  public function getRange() {
171  return $this->_range;
172  }
173 
180  public function setRange($value = null) {
181  if (!is_null($value)) {
182  $this->_range = $value;
183  }
184  return $this;
185  }
186 
192  public function getLocalOnly() {
193  return $this->_localOnly;
194  }
195 
202  public function setLocalOnly($value = false) {
203  $this->_localOnly = $value;
204  return $this;
205  }
206 
214  public static function resolveRange($pNamedRange = '', PHPExcel_Worksheet $pSheet) {
215  return $pSheet->getParent()->getNamedRange($pNamedRange, $pSheet);
216  }
217 
221  public function __clone() {
222  $vars = get_object_vars($this);
223  foreach ($vars as $key => $value) {
224  if (is_object($value)) {
225  $this->$key = clone $value;
226  } else {
227  $this->$key = $value;
228  }
229  }
230  }
231 }