Change removeComment to use CellCoordinate

This commit is contained in:
Dams 2022-06-09 09:08:02 +02:00 committed by GitHub
parent 391e6308d7
commit 13437384af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 9 deletions

View File

@ -2582,19 +2582,28 @@ class Worksheet implements IComparable
return $this;
}
/**
* Remove comment.
* Remove comment from cell.
*
* @param int $columnIndex Numeric column coordinate of the cell
* @param int $row Numeric row coordinate of the cell
* @param array<int>|CellAddress|string $cellCoordinate Coordinate of the cell as a string, eg: 'C5';
* or as an array of [$columnIndex, $row] (e.g. [3, 5]), or a CellAddress object.
*
* @return Comment
*/
public function removeCommentByColumnAndRow($columnIndex, $row)
public function removeComment($cellCoordinate)
{
$pCellCoordinate = strtoupper(Coordinate::stringFromColumnIndex($columnIndex) . $row);
if(isset($this->comments[$pCellCoordinate])) {
unset($this->comments[$pCellCoordinate]);
$cellAddress = Functions::trimSheetFromCellReference(Validations::validateCellAddress($cellCoordinate));
if (Coordinate::coordinateIsRange($cellAddress)) {
throw new Exception('Cell coordinate string can not be a range of cells.');
} elseif (strpos($cellAddress, '$') !== false) {
throw new Exception('Cell coordinate string must not be absolute.');
} elseif ($cellAddress == '') {
throw new Exception('Cell coordinate can not be zero-length string.');
}
// Check if we have a comment for this cell and delete it
if (isset($this->comments[$cellAddress])) {
unset($this->comments[$cellAddress]);
}
}