diff --git a/CHANGELOG.md b/CHANGELOG.md index 4dd2f89b..8f3f454d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,7 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org). ### Fixed -- Nothing +- Xls Reader resolving absolute named ranges to relative ranges [Issue #2826](https://github.com/PHPOffice/PhpSpreadsheet/issues/2826) [PR #2827](https://github.com/PHPOffice/PhpSpreadsheet/pull/2827) ## 1.23.0 - 2022-04-24 diff --git a/src/PhpSpreadsheet/Reader/Xls.php b/src/PhpSpreadsheet/Reader/Xls.php index d1f14ae1..af1104f5 100644 --- a/src/PhpSpreadsheet/Reader/Xls.php +++ b/src/PhpSpreadsheet/Reader/Xls.php @@ -1297,11 +1297,10 @@ class Xls extends BaseReader ($docSheet = $this->spreadsheet->getSheetByName(trim($explodes[0], "'"))) ) { $extractedRange = $explodes[1]; - $extractedRange = str_replace('$', '', $extractedRange); - $localOnly = ($definedName['scope'] == 0) ? false : true; + $localOnly = ($definedName['scope'] === 0) ? false : true; - $scope = ($definedName['scope'] == 0) ? null : $this->spreadsheet->getSheetByName($this->sheets[$definedName['scope'] - 1]['name']); + $scope = ($definedName['scope'] === 0) ? null : $this->spreadsheet->getSheetByName($this->sheets[$definedName['scope'] - 1]['name']); $this->spreadsheet->addNamedRange(new NamedRange((string) $definedName['name'], $docSheet, $extractedRange, $localOnly, $scope)); } diff --git a/tests/PhpSpreadsheetTests/Reader/Xls/DefinedNameTest.php b/tests/PhpSpreadsheetTests/Reader/Xls/DefinedNameTest.php new file mode 100644 index 00000000..c9561580 --- /dev/null +++ b/tests/PhpSpreadsheetTests/Reader/Xls/DefinedNameTest.php @@ -0,0 +1,22 @@ +load($filename); + $sheet = $spreadsheet->getActiveSheet(); + self::assertSame($sheet->getCell('A7')->getCalculatedValue(), $sheet->getCell('B7')->getCalculatedValue()); + self::assertSame($sheet->getCell('A8')->getCalculatedValue(), $sheet->getCell('B8')->getCalculatedValue()); + self::assertSame($sheet->getCell('A9')->getCalculatedValue(), $sheet->getCell('B9')->getCalculatedValue()); + $spreadsheet->disconnectWorksheets(); + } +} diff --git a/tests/data/Reader/XLS/DefinedNameTest.xls b/tests/data/Reader/XLS/DefinedNameTest.xls new file mode 100644 index 00000000..23be0c91 Binary files /dev/null and b/tests/data/Reader/XLS/DefinedNameTest.xls differ