Skip to content

Commit 1343738

Browse files
authored
Change removeComment to use CellCoordinate
1 parent 391e630 commit 1343738

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

src/PhpSpreadsheet/Worksheet/Worksheet.php

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2581,22 +2581,31 @@ public function setComments(array $comments)
25812581

25822582
return $this;
25832583
}
2584-
25852584

25862585
/**
2587-
* Remove comment.
2586+
* Remove comment from cell.
25882587
*
2589-
* @param int $columnIndex Numeric column coordinate of the cell
2590-
* @param int $row Numeric row coordinate of the cell
2588+
* @param array<int>|CellAddress|string $cellCoordinate Coordinate of the cell as a string, eg: 'C5';
2589+
* or as an array of [$columnIndex, $row] (e.g. [3, 5]), or a CellAddress object.
25912590
*
2591+
* @return Comment
25922592
*/
2593-
public function removeCommentByColumnAndRow($columnIndex, $row)
2593+
public function removeComment($cellCoordinate)
25942594
{
2595-
$pCellCoordinate = strtoupper(Coordinate::stringFromColumnIndex($columnIndex) . $row);
2596-
if(isset($this->comments[$pCellCoordinate])) {
2597-
unset($this->comments[$pCellCoordinate]);
2595+
$cellAddress = Functions::trimSheetFromCellReference(Validations::validateCellAddress($cellCoordinate));
2596+
2597+
if (Coordinate::coordinateIsRange($cellAddress)) {
2598+
throw new Exception('Cell coordinate string can not be a range of cells.');
2599+
} elseif (strpos($cellAddress, '$') !== false) {
2600+
throw new Exception('Cell coordinate string must not be absolute.');
2601+
} elseif ($cellAddress == '') {
2602+
throw new Exception('Cell coordinate can not be zero-length string.');
2603+
}
2604+
// Check if we have a comment for this cell and delete it
2605+
if (isset($this->comments[$cellAddress])) {
2606+
unset($this->comments[$cellAddress]);
25982607
}
2599-
}
2608+
}
26002609

26012610
/**
26022611
* Get comment for cell.

0 commit comments

Comments
 (0)