Merge pull request #2827 from PHPOffice/Issue-2826_Xls-Reader-Converting-Named-Ranges-to-Relative
Fix issue with Xls Reader converting all named ranges from absolute to relative
This commit is contained in:
commit
ce940a35e9
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xls;
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\Reader\Xls;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class DefinedNameTest extends TestCase
|
||||
{
|
||||
public function testAbsoluteNamedRanges(): void
|
||||
{
|
||||
// Named Ranges were being converted from absolute to relative
|
||||
$filename = 'tests/data/Reader/XLS/DefinedNameTest.xls';
|
||||
$reader = new Xls();
|
||||
$spreadsheet = $reader->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();
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Loading…
Reference in New Issue