Differences Between: [Versions 400 and 402]
1 <?php 2 3 namespace PhpOffice\PhpSpreadsheet\Reader\Ods; 4 5 use DOMElement; 6 use PhpOffice\PhpSpreadsheet\DefinedName; 7 use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet; 8 9 class DefinedNames extends BaseLoader 10 { 11 public function read(DOMElement $workbookData): void 12 { 13 $this->readDefinedRanges($workbookData); 14 $this->readDefinedExpressions($workbookData); 15 } 16 17 /** 18 * Read any Named Ranges that are defined in this spreadsheet. 19 */ 20 protected function readDefinedRanges(DOMElement $workbookData): void 21 { 22 $namedRanges = $workbookData->getElementsByTagNameNS($this->tableNs, 'named-range'); 23 foreach ($namedRanges as $definedNameElement) { 24 $definedName = $definedNameElement->getAttributeNS($this->tableNs, 'name'); 25 $baseAddress = $definedNameElement->getAttributeNS($this->tableNs, 'base-cell-address'); 26 $range = $definedNameElement->getAttributeNS($this->tableNs, 'cell-range-address'); 27 28 $baseAddress = FormulaTranslator::convertToExcelAddressValue($baseAddress); 29 $range = FormulaTranslator::convertToExcelAddressValue($range); 30 31 $this->addDefinedName($baseAddress, $definedName, $range); 32 } 33 } 34 35 /** 36 * Read any Named Formulae that are defined in this spreadsheet. 37 */ 38 protected function readDefinedExpressions(DOMElement $workbookData): void 39 { 40 $namedExpressions = $workbookData->getElementsByTagNameNS($this->tableNs, 'named-expression'); 41 foreach ($namedExpressions as $definedNameElement) { 42 $definedName = $definedNameElement->getAttributeNS($this->tableNs, 'name'); 43 $baseAddress = $definedNameElement->getAttributeNS($this->tableNs, 'base-cell-address'); 44 $expression = $definedNameElement->getAttributeNS($this->tableNs, 'expression'); 45 46 $baseAddress = FormulaTranslator::convertToExcelAddressValue($baseAddress); 47 $expression = substr($expression, strpos($expression, ':=') + 1); 48 $expression = FormulaTranslator::convertToExcelFormulaValue($expression); 49 50 $this->addDefinedName($baseAddress, $definedName, $expression); 51 } 52 } 53 54 /** 55 * Assess scope and store the Defined Name. 56 */ 57 private function addDefinedName(string $baseAddress, string $definedName, string $value): void 58 { 59 [$sheetReference] = Worksheet::extractSheetTitle($baseAddress, true); 60 $worksheet = $this->spreadsheet->getSheetByName($sheetReference); 61 // Worksheet might still be null if we're only loading selected sheets rather than the full spreadsheet 62 if ($worksheet !== null) { 63 $this->spreadsheet->addDefinedName(DefinedName::createInstance((string) $definedName, $worksheet, $value)); 64 } 65 } 66 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body