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
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.
Source
Thrown at src/PhpSpreadsheet/Cell/Coordinate.php:125
return $worksheet . '$' . $cellAddress;
} elseif (ctype_alpha($cellAddress)) {
return $worksheet . '$' . strtoupper($cellAddress);
}
return $worksheet . self::absoluteCoordinate($cellAddress);
}
/**
* Make string coordinate absolute.
*
* @param string $cellAddress e.g. 'A1'
*
* @return string Absolute coordinate e.g. '$A$1'
*/
public static function absoluteCoordinate(string $cellAddress): string
{
if (self::coordinateIsRange($cellAddress)) {
throw new Exception('Cell coordinate string can not be a range of cells');
}
// Split out any worksheet name from the coordinate
[$worksheet, $cellAddress] = Worksheet::extractSheetTitle($cellAddress, true);
if ($worksheet > '') {
$worksheet .= '!';
}
// Create absolute coordinate
[$column, $row] = self::coordinateFromString($cellAddress ?? 'A1');
$column = ltrim($column, '$');
$row = ltrim($row, '$');
return $worksheet . '$' . $column . '$' . $row;
}
/**
* Split range into coordinate strings, using comma for unionView on GitHub (pinned to 65b080eef4)
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
Example fix
// before
$abs = Coordinate::absoluteCoordinate('A1:B2'); // throws
// after
$parts = explode(':', 'A1:B2');
$abs = Coordinate::absoluteCoordinate($parts[0]) . ':' . Coordinate::absoluteCoordinate($parts[1]); // $A$1:$B$2 Defensive patterns
Strategy: validation
Validate before calling
if (Coordinate::coordinateIsRange($address)) {
$parts = explode(':', $address);
$absolute = Coordinate::absoluteCoordinate($parts[0]) . ':' . Coordinate::absoluteCoordinate($parts[1]);
} else {
$absolute = Coordinate::absoluteCoordinate($address);
} Type guard
function isSingleCellAddress(string $address): bool
{
return !Coordinate::coordinateIsRange($address);
} Try / catch
null
Prevention
- 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
When it happens
Trigger: absoluteCoordinate('A1:B2'); feeding a range captured from AutoFilter, merged cells, or getSelectedCells() (which returns ranges like 'A1:C3') into the single-cell helper.
Common situations: 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.
Related errors
- Range does not contain any information
- Each array entry must be an array
- Row and Column Ids must be positive integer values
- Cell coordinate string must not be absolute.
- #NUM!
AI-assisted analysis of PHPOffice/PhpSpreadsheet@65b080eef4 (2026-08-17).
Data as JSON: /api/errors/7f00d8aeed1bca1b.
Report an issue: GitHub.