PHPOffice/PhpSpreadsheet · error · PhpOffice\PhpSpreadsheet\Exception
Cell coordinate string can not be a range of cells.
Error message
Cell coordinate string can not be a range of cells.
What it means
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.
Source
Thrown at src/PhpSpreadsheet/Worksheet/Worksheet.php:1274
$namedRange = $this->validateNamedRange($coordinate, true);
if ($namedRange !== null) {
$sheet = $namedRange->getWorksheet();
if ($sheet === null) {
throw new Exception('Sheet not found for named range: ' . $namedRange->getName());
}
$cellCoordinate = ltrim(substr($namedRange->getValue(), (int) strrpos($namedRange->getValue(), '!')), '!');
$finalCoordinate = str_replace('$', '', $cellCoordinate);
}
}
if ($sheet === null || $finalCoordinate === null) {
$sheet = $this;
$finalCoordinate = strtoupper($coordinate);
}
if (Coordinate::coordinateIsRange($finalCoordinate)) {
throw new Exception('Cell coordinate string can not be a range of cells.');
}
$finalCoordinate = str_replace('$', '', $finalCoordinate);
return [$sheet, $finalCoordinate];
}
/**
* Get an existing cell at a specific coordinate, or null.
*
* @param string $coordinate Coordinate of the cell, eg: 'A1'
*
* @return null|Cell Cell that was found or null
*/
private function getCellOrNull(string $coordinate): ?Cell
{
// Check cell collection
if ($this->cellCollection->has($coordinate)) {
return $this->cellCollection->get($coordinate);View on GitHub (pinned to 65b080eef4)
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
Example fix
// before
$value = $sheet->getCell('A1:B2')->getValue(); // throws
// after
$topLeft = explode(':', 'A1:B2')[0];
$value = $sheet->getCell($topLeft)->getValue();
// or for the whole block:
$values = $sheet->rangeToArray('A1:B2'); Defensive patterns
Strategy: validation
Validate before calling
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
if (Coordinate::coordinateIsRange(strtoupper($ref))) {
$values = $sheet->rangeToArray($ref); // or take explode(':', $ref)[0]
} else {
$cell = $sheet->getCell($ref);
} Prevention
- 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
When it happens
Trigger: $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.
Common situations: 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).
Related errors
- Cannot get column when cell is not bound to a worksheet
- Coordinate no longer exists
- #VALUE!
- Invalid R1C1-format Cell Reference
- Invalid A1-format Cell Reference
AI-assisted analysis of PHPOffice/PhpSpreadsheet@65b080eef4 (2026-08-17).
Data as JSON: /api/errors/7d6ffebca4e7d232.
Report an issue: GitHub.