{"record":{"id":"7f00d8aeed1bca1b","repo":"PHPOffice/PhpSpreadsheet","slug":"cell-coordinate-string-can-not-be-a-range-of-cells","errorCode":null,"errorMessage":"Cell coordinate string can not be a range of cells","messagePattern":"Cell coordinate string can not be a range of cells","errorType":"exception","errorClass":"PhpOffice\\PhpSpreadsheet\\Exception","httpStatus":null,"severity":"error","filePath":"src/PhpSpreadsheet/Cell/Coordinate.php","lineNumber":125,"sourceCode":"            return $worksheet . '$' . $cellAddress;\n        } elseif (ctype_alpha($cellAddress)) {\n            return $worksheet . '$' . strtoupper($cellAddress);\n        }\n\n        return $worksheet . self::absoluteCoordinate($cellAddress);\n    }\n\n    /**\n     * Make string coordinate absolute.\n     *\n     * @param string $cellAddress e.g. 'A1'\n     *\n     * @return string Absolute coordinate        e.g. '$A$1'\n     */\n    public static function absoluteCoordinate(string $cellAddress): string\n    {\n        if (self::coordinateIsRange($cellAddress)) {\n            throw new Exception('Cell coordinate string can not be a range of cells');\n        }\n\n        // Split out any worksheet name from the coordinate\n        [$worksheet, $cellAddress] = Worksheet::extractSheetTitle($cellAddress, true);\n        if ($worksheet > '') {\n            $worksheet .= '!';\n        }\n\n        // Create absolute coordinate\n        [$column, $row] = self::coordinateFromString($cellAddress ?? 'A1');\n        $column = ltrim($column, '$');\n        $row = ltrim($row, '$');\n\n        return $worksheet . '$' . $column . '$' . $row;\n    }\n\n    /**\n     * Split range into coordinate strings, using comma for union","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/PHPOffice/PhpSpreadsheet/blob/65b080eef4d9fd11a5796135ab145883e5c3d6a6/src/PhpSpreadsheet/Cell/Coordinate.php#L107-L143","documentation":"Coordinate::absoluteCoordinate() converts a single-cell address like 'A1' (optionally sheet-qualified) into its absolute form '$A$1'. It explicitly rejects ranges because there is no single absolute form for 'A1:B2'; callers must split the range and absolutize each endpoint themselves.","triggerScenarios":"absoluteCoordinate('A1:B2'); feeding a range captured from AutoFilter, merged cells, or getSelectedCells() (which returns ranges like 'A1:C3') into the single-cell helper.","commonSituations":"Code that assumes user selections are always single cells; copy/paste of style anchors where the source happened to be a range; sheet-qualified inputs like 'Sheet1!A1:B2' after extractSheetTitle leaves a range.","solutions":["Branch on Coordinate::coordinateIsRange($address) and handle the range case: explode on ':' and absolutize each endpoint, then rejoin with ':'","Use Coordinate::absolute() if you need a general-purpose absolutizer that accepts ranges","Validate that user/selection input is a single cell before calling single-cell helpers"],"exampleFix":"// before\n$abs = Coordinate::absoluteCoordinate('A1:B2'); // throws\n\n// after\n$parts = explode(':', 'A1:B2');\n$abs = Coordinate::absoluteCoordinate($parts[0]) . ':' . Coordinate::absoluteCoordinate($parts[1]); // $A$1:$B$2","handlingStrategy":"validation","validationCode":"if (Coordinate::coordinateIsRange($address)) {\n    $parts = explode(':', $address);\n    $absolute = Coordinate::absoluteCoordinate($parts[0]) . ':' . Coordinate::absoluteCoordinate($parts[1]);\n} else {\n    $absolute = Coordinate::absoluteCoordinate($address);\n}","typeGuard":"function isSingleCellAddress(string $address): bool\n{\n    return !Coordinate::coordinateIsRange($address);\n}","tryCatchPattern":"null","preventionTips":["Branch on Coordinate::coordinateIsRange() before calling single-cell helpers","Treat any user selection or getSelectedCells() result as potentially a range","Use Coordinate::absolute() when the input may legitimately be a range"],"tags":["phpspreadsheet","coordinate","range","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"}