{"record":{"id":"7d6ffebca4e7d232","repo":"PHPOffice/PhpSpreadsheet","slug":"cell-coordinate-string-can-not-be-a-range-of-cells-7d6ffe","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/Worksheet/Worksheet.php","lineNumber":1274,"sourceCode":"            $namedRange = $this->validateNamedRange($coordinate, true);\n            if ($namedRange !== null) {\n                $sheet = $namedRange->getWorksheet();\n                if ($sheet === null) {\n                    throw new Exception('Sheet not found for named range: ' . $namedRange->getName());\n                }\n\n                $cellCoordinate = ltrim(substr($namedRange->getValue(), (int) strrpos($namedRange->getValue(), '!')), '!');\n                $finalCoordinate = str_replace('$', '', $cellCoordinate);\n            }\n        }\n\n        if ($sheet === null || $finalCoordinate === null) {\n            $sheet = $this;\n            $finalCoordinate = strtoupper($coordinate);\n        }\n\n        if (Coordinate::coordinateIsRange($finalCoordinate)) {\n            throw new Exception('Cell coordinate string can not be a range of cells.');\n        }\n        $finalCoordinate = str_replace('$', '', $finalCoordinate);\n\n        return [$sheet, $finalCoordinate];\n    }\n\n    /**\n     * Get an existing cell at a specific coordinate, or null.\n     *\n     * @param string $coordinate Coordinate of the cell, eg: 'A1'\n     *\n     * @return null|Cell Cell that was found or null\n     */\n    private function getCellOrNull(string $coordinate): ?Cell\n    {\n        // Check cell collection\n        if ($this->cellCollection->has($coordinate)) {\n            return $this->cellCollection->get($coordinate);","sourceCodeStart":1256,"sourceCodeEnd":1292,"githubUrl":"https://github.com/PHPOffice/PhpSpreadsheet/blob/65b080eef4d9fd11a5796135ab145883e5c3d6a6/src/PhpSpreadsheet/Worksheet/Worksheet.php#L1256-L1292","documentation":"After Worksheet's coordinate resolver settles on a final sheet + coordinate (directly, via 'Sheet!A1', or via a named range), it runs Coordinate::coordinateIsRange() and throws if the coordinate still describes multiple cells (contains ':'). Cell APIs address exactly one cell; ranges must go through the range APIs.","triggerScenarios":"$sheet->getCell('A1:B2'); $sheet->getCell('Summary!A1:B2'); $sheet->getCell('MyRange') where the named range's value is a multi-cell range like Sheet1!$A$1:$B$2.","commonSituations":"Pointing getCell() at a named range that covers a block; passing a user-entered range string straight to getCell(); assuming getCell returns the top-left value of a range (it does not).","solutions":["Take a single cell: for ranges use explode(':', $ref)[0] (or Coordinate::splitRange()[0][0]) to get the top-left address, e.g. getCell('A1')","Read blocks with the range APIs: $sheet->rangeToArray('A1:B2') / toArray()","If a named range resolves to a block, decide explicitly which cell you want (usually the first) instead of passing the whole range"],"exampleFix":"// before\n$value = $sheet->getCell('A1:B2')->getValue(); // throws\n\n// after\n$topLeft = explode(':', 'A1:B2')[0];\n$value = $sheet->getCell($topLeft)->getValue();\n// or for the whole block:\n$values = $sheet->rangeToArray('A1:B2');","handlingStrategy":"validation","validationCode":"use PhpOffice\\PhpSpreadsheet\\Cell\\Coordinate;\n\nif (Coordinate::coordinateIsRange(strtoupper($ref))) {\n    $values = $sheet->rangeToArray($ref); // or take explode(':', $ref)[0]\n} else {\n    $cell = $sheet->getCell($ref);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never forward raw user-typed range strings to getCell()","For named ranges, inspect getValue() and branch single-cell vs block","Standardize on rangeToArray()/toArray() for any ':'-containing reference"],"tags":["phpspreadsheet","cell","coordinate","range-vs-cell","validation"],"backgroundTag":"invalid-cell-reference","analyzedSha":"65b080eef4d9fd11a5796135ab145883e5c3d6a6","analyzedAt":"2026-08-17T05:40:41.646Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}