PHPOffice/PhpSpreadsheet · error · PhpOffice\PhpSpreadsheet\Exception
Cell coordinate string must not be absolute.
Error message
Cell coordinate string must not be absolute.
What it means
removeComment() looks comments up by plain relative coordinate ('C5'), so addresses containing '$' absolute markers ('$A$1', 'B$3') are rejected. The check exists because '$A$1' would otherwise miss the stored key 'A1' and silently do nothing.
Source
Thrown at src/PhpSpreadsheet/Worksheet/Worksheet.php:2973
return $this;
}
/**
* Remove comment from cell.
*
* @param array{0: int, 1: 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 $this
*/
public function removeComment(CellAddress|string|array $cellCoordinate): self
{
$cellAddress = Functions::trimSheetFromCellReference(Validations::validateCellAddress($cellCoordinate));
if (Coordinate::coordinateIsRange($cellAddress)) {
throw new Exception('Cell coordinate string can not be a range of cells.');
} elseif (str_contains($cellAddress, '$')) {
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]);
}
return $this;
}
/**
* Get comment for cell.
*
* @param array{0: int, 1: 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.
*/
public function getComment(CellAddress|string|array $cellCoordinate, bool $attachNew = true): CommentView on GitHub (pinned to 65b080eef4)
Solutions
- Strip the markers: $coord = str_replace('$', '', $coord); then removeComment($coord).
- Keep plain 'A1' strings for data-access APIs and build absolute refs only when generating formulas.
- Pass [columnIndex, row] arrays or CellAddress objects, which cannot carry '$' markers.
Example fix
// before
$sheet->removeComment('$B$3'); // throws: absolute
// after
$sheet->removeComment('B3');
// or normalize any incoming ref:
$sheet->removeComment(str_replace('$', '', $incomingRef)); Defensive patterns
Strategy: validation
Validate before calling
$coord = str_replace('$', '', $incomingRef); // strip absolute markers
$sheet->removeComment($coord); Type guard
/** Absolute markers are not part of the stored comment keys. */
function isRelativeCoordinate(string $address): bool
{
return !str_contains($address, '$');
} Prevention
- Strip '$' with str_replace at the boundary where formula-style refs enter data-access code.
- Use [columnIndex, row] arrays or CellAddress objects to avoid '$' entirely.
- Keep Coordinate::absoluteCoordinate() calls on the formula-generation side only.
When it happens
Trigger: removeComment('$A$1') or removeComment('B$3'); addresses built with Coordinate::absoluteCoordinate() or copied out of formula strings; refs pasted from Excel's formula bar.
Common situations: Reusing formula-building helpers that emit absolute references as if they were plain coordinates; consuming refs from mixed sources in one codebase.
Related errors
- Cell coordinate can not be zero-length string.
- Cell coordinate string can not be a range of cells
- Freeze pane can not be set on a range of cells.
- Rows can only be inserted before at least row 1.
- Column references should not be numeric.
AI-assisted analysis of PHPOffice/PhpSpreadsheet@65b080eef4 (2026-08-17).
Data as JSON: /api/errors/44d58692ad312b22.
Report an issue: GitHub.