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.

Reimplemented in PhpOffice\PhpSpreadsheet\NamedFormula.

Definition at line 56 of file DefinedName.php.

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.
static testIfFormula(string $value)

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

+ 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.

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

References $key.

◆ createInstance()

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

Create a new defined name, either a range or a formula.

Definition at line 84 of file DefinedName.php.

90 : self {
91 $value = (string) $value;
93 if ($isFormula) {
94 return new NamedFormula($name, $worksheet, $value, $localOnly, $scope);
95 }
96
97 return new NamedRange($name, $worksheet, $value, $localOnly, $scope);
98 }

Referenced by PhpOffice\PhpSpreadsheet\Reader\Ods\DefinedNames\addDefinedName(), and PhpOffice\PhpSpreadsheet\Reader\Gnumeric\processDefinedNames().

+ Here is the caller graph for this function:

◆ getLocalOnly()

PhpOffice\PhpSpreadsheet\DefinedName::getLocalOnly ( )

Get localOnly.

Definition at line 198 of file DefinedName.php.

198 : bool
199 {
200 return $this->localOnly;
201 }

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

+ Here is the caller graph for this function:

◆ getName()

◆ getScope()

PhpOffice\PhpSpreadsheet\DefinedName::getScope ( )

◆ getValue()

PhpOffice\PhpSpreadsheet\DefinedName::getValue ( )

◆ getWorksheet()

◆ isFormula()

PhpOffice\PhpSpreadsheet\DefinedName::isFormula ( )

Identify whether this is a named range or a named formula.

Definition at line 236 of file DefinedName.php.

236 : bool
237 {
238 return $this->isFormula;
239 }

Referenced by PhpOffice\PhpSpreadsheet\DefinedName\__construct(), PhpOffice\PhpSpreadsheet\Calculation\Calculation\evaluateDefinedName(), PhpOffice\PhpSpreadsheet\Spreadsheet\getNamedFormulae(), and PhpOffice\PhpSpreadsheet\Spreadsheet\getNamedRanges().

+ Here is the caller graph for this function:

◆ 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.

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 }

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

+ 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.

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.

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.

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

+ 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.

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.

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.

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.

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 }

Referenced by PhpOffice\PhpSpreadsheet\DefinedName\__construct().

+ Here is the caller graph for this function:

Field Documentation

◆ $isFormula

PhpOffice\PhpSpreadsheet\DefinedName::$isFormula
protected

Definition at line 51 of file DefinedName.php.

◆ $localOnly

PhpOffice\PhpSpreadsheet\DefinedName::$localOnly
protected

◆ $name

◆ $scope

◆ $value

◆ $worksheet

PhpOffice\PhpSpreadsheet\DefinedName::$worksheet
protected

◆ 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: