ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
PhpOffice\PhpSpreadsheet\DefinedName Class Reference
+ Inheritance diagram for PhpOffice\PhpSpreadsheet\DefinedName:
+ Collaboration diagram for PhpOffice\PhpSpreadsheet\DefinedName:

Public Member Functions

 __construct (string $name, ?Worksheet $worksheet=null, ?string $value=null, bool $localOnly=false, ?Worksheet $scope=null)
 Create a new Defined Name. More...
 
 getName ()
 Get name. More...
 
 setName (string $name)
 Set name. More...
 
 getWorksheet ()
 Get worksheet. More...
 
 setWorksheet (?Worksheet $value)
 Set worksheet. More...
 
 getValue ()
 Get range or formula value. More...
 
 setValue (string $value)
 Set range or formula value. More...
 
 getLocalOnly ()
 Get localOnly. More...
 
 setLocalOnly (bool $value)
 Set localOnly. More...
 
 getScope ()
 Get scope. More...
 
 setScope (?Worksheet $value)
 Set scope. More...
 
 isFormula ()
 Identify whether this is a named range or a named formula. More...
 
 __clone ()
 Implement PHP __clone to create a deep clone, not just a shallow copy. More...
 

Static Public Member Functions

static createInstance (string $name, ?Worksheet $worksheet=null, ?string $value=null, bool $localOnly=false, ?Worksheet $scope=null)
 Create a new defined name, either a range or a formula. More...
 
static testIfFormula (string $value)
 
static resolveName (string $pDefinedName, Worksheet $pSheet, string $sheetName='')
 Resolve a named range to a regular cell range or formula. More...
 

Protected Attributes

const REGEXP_IDENTIFY_FORMULA = '[^_\p{N}\p{L}:, \$\'!]'
 
 $name
 
 $worksheet
 
 $value
 
 $localOnly
 
 $scope
 
 $isFormula
 

Detailed Description

Definition at line 7 of file DefinedName.php.

Constructor & Destructor Documentation

◆ __construct()

PhpOffice\PhpSpreadsheet\DefinedName::__construct ( string  $name,
?Worksheet  $worksheet = null,
?string  $value = null,
bool  $localOnly = false,
?Worksheet  $scope = null 
)

Create a new Defined Name.

Definition at line 56 of file DefinedName.php.

References PhpOffice\PhpSpreadsheet\DefinedName\$localOnly, PhpOffice\PhpSpreadsheet\DefinedName\$name, PhpOffice\PhpSpreadsheet\DefinedName\$scope, PhpOffice\PhpSpreadsheet\DefinedName\$value, PhpOffice\PhpSpreadsheet\DefinedName\$worksheet, and PhpOffice\PhpSpreadsheet\DefinedName\isFormula().

62  {
63  if ($worksheet === null) {
65  }
66 
67  // Set local members
68  $this->name = $name;
69  $this->worksheet = $worksheet;
70  $this->value = (string) $value;
71  $this->localOnly = $localOnly;
72  // If local only, then the scope will be set to worksheet unless a scope is explicitly set
73  $this->scope = ($localOnly === true) ? (($scope === null) ? $worksheet : $scope) : null;
74  // If the range string contains characters that aren't associated with the range definition (A-Z,1-9
75  // for cell references, and $, or the range operators (colon comma or space), quotes and ! for
76  // worksheet names
77  // then this is treated as a named formula, and not a named range
78  $this->isFormula = self::testIfFormula($this->value);
79  }
isFormula()
Identify whether this is a named range or a named formula.
+ Here is the call graph for this function:

Member Function Documentation

◆ __clone()

PhpOffice\PhpSpreadsheet\DefinedName::__clone ( )

Implement PHP __clone to create a deep clone, not just a shallow copy.

Definition at line 261 of file DefinedName.php.

References $key, and PhpOffice\PhpSpreadsheet\DefinedName\$value.

262  {
263  $vars = get_object_vars($this);
264  foreach ($vars as $key => $value) {
265  if (is_object($value)) {
266  $this->$key = clone $value;
267  } else {
268  $this->$key = $value;
269  }
270  }
271  }
$key
Definition: croninfo.php:18

◆ createInstance()

static PhpOffice\PhpSpreadsheet\DefinedName::createInstance ( string  $name,
?Worksheet  $worksheet = null,
?string  $value = null,
bool  $localOnly = false,
?Worksheet  $scope = null 
)
static

◆ getLocalOnly()

PhpOffice\PhpSpreadsheet\DefinedName::getLocalOnly ( )

Get localOnly.

Definition at line 198 of file DefinedName.php.

References PhpOffice\PhpSpreadsheet\DefinedName\$localOnly.

Referenced by PhpOffice\PhpSpreadsheet\Writer\Xlsx\DefinedNames\writeDefinedName().

198  : bool
199  {
200  return $this->localOnly;
201  }
+ Here is the caller graph for this function:

◆ getName()

◆ getScope()

PhpOffice\PhpSpreadsheet\DefinedName::getScope ( )

◆ getValue()

◆ getWorksheet()

◆ isFormula()

PhpOffice\PhpSpreadsheet\DefinedName::isFormula ( )

◆ resolveName()

static PhpOffice\PhpSpreadsheet\DefinedName::resolveName ( string  $pDefinedName,
Worksheet  $pSheet,
string  $sheetName = '' 
)
static

Resolve a named range to a regular cell range or formula.

Definition at line 244 of file DefinedName.php.

References PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\getParent().

Referenced by PhpOffice\PhpSpreadsheet\Calculation\LookupRef\Helpers\extractCellAddresses(), PhpOffice\PhpSpreadsheet\Calculation\Calculation\extractNamedRange(), PhpOffice\PhpSpreadsheet\Calculation\Calculation\processTokenStack(), and PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\validateNamedRange().

244  : ?self
245  {
246  if ($sheetName === '') {
247  $pSheet2 = $pSheet;
248  } else {
249  $pSheet2 = $pSheet->getParent()->getSheetByName($sheetName);
250  if ($pSheet2 === null) {
251  return null;
252  }
253  }
254 
255  return $pSheet->getParent()->getDefinedName($pDefinedName, $pSheet2);
256  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setLocalOnly()

PhpOffice\PhpSpreadsheet\DefinedName::setLocalOnly ( bool  $value)

Set localOnly.

Definition at line 206 of file DefinedName.php.

References PhpOffice\PhpSpreadsheet\DefinedName\$value.

206  : self
207  {
208  $this->localOnly = $value;
209  $this->scope = $value ? $this->worksheet : null;
210 
211  return $this;
212  }

◆ setName()

PhpOffice\PhpSpreadsheet\DefinedName::setName ( string  $name)

Set name.

Definition at line 135 of file DefinedName.php.

References PhpOffice\PhpSpreadsheet\DefinedName\$name, and PhpOffice\PhpSpreadsheet\ReferenceHelper\getInstance().

135  : self
136  {
137  if (!empty($name)) {
138  // Old title
139  $oldTitle = $this->name;
140 
141  // Re-attach
142  if ($this->worksheet !== null) {
143  $this->worksheet->getParent()->removeNamedRange($this->name, $this->worksheet);
144  }
145  $this->name = $name;
146 
147  if ($this->worksheet !== null) {
148  $this->worksheet->getParent()->addNamedRange($this);
149  }
150 
151  // New title
152  $newTitle = $this->name;
153  ReferenceHelper::getInstance()->updateNamedFormulas($this->worksheet->getParent(), $oldTitle, $newTitle);
154  }
155 
156  return $this;
157  }
static getInstance()
Get an instance of this class.
+ Here is the call graph for this function:

◆ setScope()

PhpOffice\PhpSpreadsheet\DefinedName::setScope ( ?Worksheet  $value)

Set scope.

Definition at line 225 of file DefinedName.php.

References PhpOffice\PhpSpreadsheet\DefinedName\$value.

225  : self
226  {
227  $this->scope = $value;
228  $this->localOnly = $value !== null;
229 
230  return $this;
231  }

◆ setValue()

PhpOffice\PhpSpreadsheet\DefinedName::setValue ( string  $value)

Set range or formula value.

Definition at line 188 of file DefinedName.php.

References PhpOffice\PhpSpreadsheet\DefinedName\$value.

188  : self
189  {
190  $this->value = $value;
191 
192  return $this;
193  }

◆ setWorksheet()

PhpOffice\PhpSpreadsheet\DefinedName::setWorksheet ( ?Worksheet  $value)

Set worksheet.

Definition at line 170 of file DefinedName.php.

References PhpOffice\PhpSpreadsheet\DefinedName\$value.

170  : self
171  {
172  $this->worksheet = $value;
173 
174  return $this;
175  }

◆ testIfFormula()

static PhpOffice\PhpSpreadsheet\DefinedName::testIfFormula ( string  $value)
static

Definition at line 100 of file DefinedName.php.

Referenced by PhpOffice\PhpSpreadsheet\Reader\Xlsx\getFromZipArchive().

100  : bool
101  {
102  if (substr($value, 0, 1) === '=') {
103  $value = substr($value, 1);
104  }
105 
106  if (is_numeric($value)) {
107  return true;
108  }
109 
110  $segMatcher = false;
111  foreach (explode("'", $value) as $subVal) {
112  // Only test in alternate array entries (the non-quoted blocks)
113  if (
114  ($segMatcher = !$segMatcher) &&
115  (preg_match('/' . self::REGEXP_IDENTIFY_FORMULA . '/miu', $subVal))
116  ) {
117  return true;
118  }
119  }
120 
121  return false;
122  }
+ Here is the caller graph for this function:

Field Documentation

◆ $isFormula

PhpOffice\PhpSpreadsheet\DefinedName::$isFormula
protected

◆ $localOnly

◆ $name

PhpOffice\PhpSpreadsheet\DefinedName::$name
protected

◆ $scope

◆ $value

◆ $worksheet

◆ REGEXP_IDENTIFY_FORMULA

const PhpOffice\PhpSpreadsheet\DefinedName::REGEXP_IDENTIFY_FORMULA = '[^_\p{N}\p{L}:, \$\'!]'
protected

Definition at line 9 of file DefinedName.php.


The documentation for this class was generated from the following file: