Skip to content

Commit

Permalink
Bugfix #1858; getCell() method should support named cells correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkBaker committed Feb 19, 2021
1 parent 409c05b commit 3cf2d9f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -43,6 +43,7 @@ and this project adheres to [Semantic Versioning](https://semver.org).
- Nothing.

### 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 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)
Expand Down
9 changes: 5 additions & 4 deletions src/PhpSpreadsheet/Worksheet/Worksheet.php
Expand Up @@ -1186,7 +1186,8 @@ public function getCell($pCoordinate, $createIfNotExists = true)
if (strpos($pCoordinate, '!') !== false) {
$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?
Expand All @@ -1196,7 +1197,7 @@ public function getCell($pCoordinate, $createIfNotExists = true)
) {
$namedRange = DefinedName::resolveName($pCoordinate, $this);
if ($namedRange !== null) {
$pCoordinate = $namedRange->getValue();
$pCoordinate = str_replace('$', '', $namedRange->getValue());

return $namedRange->getWorksheet()->getCell($pCoordinate, $createIfNotExists);
}
Expand Down Expand Up @@ -1296,7 +1297,7 @@ public function cellExists($pCoordinate)
) {
$namedRange = DefinedName::resolveName($pCoordinate, $this);
if ($namedRange !== null) {
$pCoordinate = $namedRange->getValue();
$pCoordinate = str_replace('$', '', $namedRange->getValue());
if ($this->getHashCode() != $namedRange->getWorksheet()->getHashCode()) {
if (!$namedRange->getLocalOnly()) {
return $namedRange->getWorksheet()->cellExists($pCoordinate);
Expand Down Expand Up @@ -2567,7 +2568,7 @@ public function namedRangeToArray($pNamedRange, $nullValue = null, $calculateFor
$namedRange = DefinedName::resolveName($pNamedRange, $this);
if ($namedRange !== null) {
$pWorkSheet = $namedRange->getWorksheet();
$pCellRange = $namedRange->getValue();
$pCellRange = str_replace('$', '', $namedRange->getValue());

return $pWorkSheet->rangeToArray($pCellRange, $nullValue, $calculateFormulas, $formatData, $returnCellRef);
}
Expand Down

0 comments on commit 3cf2d9f

Please sign in to comment.