Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add removeCommentByColumnAndRow function #2875

Merged
merged 10 commits into from
Jun 14, 2022
Prev Previous commit
Next Next commit
Change removeComment to use CellCoordinate
  • Loading branch information
dgeppo authored Jun 9, 2022
commit 13437384afd58acd64833cbd28fdf13070f82d2d
27 changes: 18 additions & 9 deletions src/PhpSpreadsheet/Worksheet/Worksheet.php
Original file line number Diff line number Diff line change
Expand Up @@ -2581,22 +2581,31 @@ public function setComments(array $comments)

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]);
}
}
}
MarkBaker marked this conversation as resolved.
Show resolved Hide resolved

/**
* Get comment for cell.
Expand Down