{"record":{"id":"44d58692ad312b22","repo":"PHPOffice/PhpSpreadsheet","slug":"cell-coordinate-string-must-not-be-absolute","errorCode":null,"errorMessage":"Cell coordinate string must not be absolute.","messagePattern":"Cell coordinate string must not be absolute\\.","errorType":"exception","errorClass":"PhpOffice\\PhpSpreadsheet\\Exception","httpStatus":null,"severity":"error","filePath":"src/PhpSpreadsheet/Worksheet/Worksheet.php","lineNumber":2973,"sourceCode":"        return $this;\n    }\n\n    /**\n     * Remove comment from cell.\n     *\n     * @param array{0: int, 1: int}|CellAddress|string $cellCoordinate Coordinate of the cell as a string, eg: 'C5';\n     *               or as an array of [$columnIndex, $row] (e.g. [3, 5]), or a CellAddress object.\n     *\n     * @return $this\n     */\n    public function removeComment(CellAddress|string|array $cellCoordinate): self\n    {\n        $cellAddress = Functions::trimSheetFromCellReference(Validations::validateCellAddress($cellCoordinate));\n\n        if (Coordinate::coordinateIsRange($cellAddress)) {\n            throw new Exception('Cell coordinate string can not be a range of cells.');\n        } elseif (str_contains($cellAddress, '$')) {\n            throw new Exception('Cell coordinate string must not be absolute.');\n        } elseif ($cellAddress == '') {\n            throw new Exception('Cell coordinate can not be zero-length string.');\n        }\n        // Check if we have a comment for this cell and delete it\n        if (isset($this->comments[$cellAddress])) {\n            unset($this->comments[$cellAddress]);\n        }\n\n        return $this;\n    }\n\n    /**\n     * Get comment for cell.\n     *\n     * @param array{0: int, 1: int}|CellAddress|string $cellCoordinate Coordinate of the cell as a string, eg: 'C5';\n     *               or as an array of [$columnIndex, $row] (e.g. [3, 5]), or a CellAddress object.\n     */\n    public function getComment(CellAddress|string|array $cellCoordinate, bool $attachNew = true): Comment","sourceCodeStart":2955,"sourceCodeEnd":2991,"githubUrl":"https://github.com/PHPOffice/PhpSpreadsheet/blob/65b080eef4d9fd11a5796135ab145883e5c3d6a6/src/PhpSpreadsheet/Worksheet/Worksheet.php#L2955-L2991","documentation":"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.","triggerScenarios":"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.","commonSituations":"Reusing formula-building helpers that emit absolute references as if they were plain coordinates; consuming refs from mixed sources in one codebase.","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."],"exampleFix":"// before\n$sheet->removeComment('$B$3'); // throws: absolute\n\n// after\n$sheet->removeComment('B3');\n// or normalize any incoming ref:\n$sheet->removeComment(str_replace('$', '', $incomingRef));","handlingStrategy":"validation","validationCode":"$coord = str_replace('$', '', $incomingRef); // strip absolute markers\n$sheet->removeComment($coord);","typeGuard":"/** Absolute markers are not part of the stored comment keys. */\nfunction isRelativeCoordinate(string $address): bool\n{\n    return !str_contains($address, '$');\n}","tryCatchPattern":null,"preventionTips":["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."],"tags":["phpspreadsheet","worksheet","comment","absolute-reference","argument-validation"],"backgroundTag":"invalid-cell-reference","analyzedSha":"65b080eef4d9fd11a5796135ab145883e5c3d6a6","analyzedAt":"2026-08-17T05:40:41.646Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}