From 32559b44a3f9c144e08357bc1860002de1b12bf2 Mon Sep 17 00:00:00 2001 From: MarkBaker Date: Sat, 30 Apr 2022 20:14:36 +0200 Subject: [PATCH] Use the call to Coordinate::coordinateFromString() to validate the coordinate passed to createNewCell() _before_ we try adding it to the Collection --- src/PhpSpreadsheet/Worksheet/Worksheet.php | 2 +- .../Worksheet/WorksheetNamedRangesTest.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/PhpSpreadsheet/Worksheet/Worksheet.php b/src/PhpSpreadsheet/Worksheet/Worksheet.php index 0baf6ecd..cb2cd06d 100644 --- a/src/PhpSpreadsheet/Worksheet/Worksheet.php +++ b/src/PhpSpreadsheet/Worksheet/Worksheet.php @@ -1336,12 +1336,12 @@ class Worksheet implements IComparable */ public function createNewCell($coordinate) { + [$column, $row] = Coordinate::coordinateFromString($coordinate); $cell = new Cell(null, DataType::TYPE_NULL, $this); $this->cellCollection->add($coordinate, $cell); $this->cellCollectionIsSorted = false; // Coordinates - [$column, $row] = Coordinate::coordinateFromString($coordinate); $aIndexes = Coordinate::indexesFromString($coordinate); if ($this->cachedHighestColumn < $aIndexes[0]) { $this->cachedHighestColumn = $aIndexes[0]; diff --git a/tests/PhpSpreadsheetTests/Worksheet/WorksheetNamedRangesTest.php b/tests/PhpSpreadsheetTests/Worksheet/WorksheetNamedRangesTest.php index 4eddb26e..b367583b 100644 --- a/tests/PhpSpreadsheetTests/Worksheet/WorksheetNamedRangesTest.php +++ b/tests/PhpSpreadsheetTests/Worksheet/WorksheetNamedRangesTest.php @@ -72,7 +72,7 @@ class WorksheetNamedRangesTest extends TestCase $namedCell = 'GOODBYE'; $this->expectException(Exception::class); -// $this->expectExceptionMessage("Invalid cell coordinate {$namedCell}"); + $this->expectExceptionMessage("Invalid cell coordinate {$namedCell}"); $worksheet = $this->spreadsheet->getActiveSheet(); $worksheet->getCell($namedCell); @@ -84,7 +84,7 @@ class WorksheetNamedRangesTest extends TestCase $ucNamedCell = strtoupper($namedCell); $this->expectException(Exception::class); -// $this->expectExceptionMessage("Invalid cell coordinate {$ucNamedCell}"); + $this->expectExceptionMessage("Invalid cell coordinate {$ucNamedCell}"); $worksheet = $this->spreadsheet->getActiveSheet(); $worksheet->getCell($namedCell);