Bugfix #1858; `getCell()` method should support named cells correctly (#1865)

Resolution for Issue [#1858](https://github.com/PHPOffice/PhpSpreadsheet/issues/1858)
This commit is contained in:
Mark Baker 2021-02-19 12:28:07 +01:00 committed by GitHub
parent 409c05b542
commit b0eb272ce1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 4 deletions

View File

@ -43,6 +43,7 @@ and this project adheres to [Semantic Versioning](https://semver.org).
- Nothing. - Nothing.
### Fixed ### Fixed
- Fixed issue with Worksheet's `getCell()` method when trying to get a cell by defined name. [#1858](https://github.com/PHPOffice/PhpSpreadsheet/issues/1858)
- Fix possible endless loop in NumberFormat Masks [#1792](https://github.com/PHPOffice/PhpSpreadsheet/issues/1792) - Fix possible endless loop in NumberFormat Masks [#1792](https://github.com/PHPOffice/PhpSpreadsheet/issues/1792)
- Fix problem resulting from literal dot inside quotes in number format masks. [PR #1830](https://github.com/PHPOffice/PhpSpreadsheet/pull/1830) - Fix problem resulting from literal dot inside quotes in number format masks. [PR #1830](https://github.com/PHPOffice/PhpSpreadsheet/pull/1830)
- Resolve Google Sheets Xlsx charts issue. Google Sheets uses oneCellAnchor positioning and does not include *Cache values in the exported Xlsx. [PR #1761](https://github.com/PHPOffice/PhpSpreadsheet/pull/1761) - Resolve Google Sheets Xlsx charts issue. Google Sheets uses oneCellAnchor positioning and does not include *Cache values in the exported Xlsx. [PR #1761](https://github.com/PHPOffice/PhpSpreadsheet/pull/1761)

View File

@ -1186,7 +1186,8 @@ class Worksheet implements IComparable
if (strpos($pCoordinate, '!') !== false) { if (strpos($pCoordinate, '!') !== false) {
$worksheetReference = self::extractSheetTitle($pCoordinate, true); $worksheetReference = self::extractSheetTitle($pCoordinate, true);
return $this->parent->getSheetByName($worksheetReference[0])->getCell(strtoupper($worksheetReference[1]), $createIfNotExists); return $this->parent->getSheetByName($worksheetReference[0])
->getCell(strtoupper($worksheetReference[1]), $createIfNotExists);
} }
// Named range? // Named range?
@ -1196,7 +1197,7 @@ class Worksheet implements IComparable
) { ) {
$namedRange = DefinedName::resolveName($pCoordinate, $this); $namedRange = DefinedName::resolveName($pCoordinate, $this);
if ($namedRange !== null) { if ($namedRange !== null) {
$pCoordinate = $namedRange->getValue(); $pCoordinate = str_replace('$', '', $namedRange->getValue());
return $namedRange->getWorksheet()->getCell($pCoordinate, $createIfNotExists); return $namedRange->getWorksheet()->getCell($pCoordinate, $createIfNotExists);
} }
@ -1296,7 +1297,7 @@ class Worksheet implements IComparable
) { ) {
$namedRange = DefinedName::resolveName($pCoordinate, $this); $namedRange = DefinedName::resolveName($pCoordinate, $this);
if ($namedRange !== null) { if ($namedRange !== null) {
$pCoordinate = $namedRange->getValue(); $pCoordinate = str_replace('$', '', $namedRange->getValue());
if ($this->getHashCode() != $namedRange->getWorksheet()->getHashCode()) { if ($this->getHashCode() != $namedRange->getWorksheet()->getHashCode()) {
if (!$namedRange->getLocalOnly()) { if (!$namedRange->getLocalOnly()) {
return $namedRange->getWorksheet()->cellExists($pCoordinate); return $namedRange->getWorksheet()->cellExists($pCoordinate);
@ -2567,7 +2568,7 @@ class Worksheet implements IComparable
$namedRange = DefinedName::resolveName($pNamedRange, $this); $namedRange = DefinedName::resolveName($pNamedRange, $this);
if ($namedRange !== null) { if ($namedRange !== null) {
$pWorkSheet = $namedRange->getWorksheet(); $pWorkSheet = $namedRange->getWorksheet();
$pCellRange = $namedRange->getValue(); $pCellRange = str_replace('$', '', $namedRange->getValue());
return $pWorkSheet->rangeToArray($pCellRange, $nullValue, $calculateFormulas, $formatData, $returnCellRef); return $pWorkSheet->rangeToArray($pCellRange, $nullValue, $calculateFormulas, $formatData, $returnCellRef);
} }