PHPOffice/PhpSpreadsheet · error · SpreadsheetException
Coordinate no longer exists
Error message
Coordinate no longer exists
What it means
getCoordinate() asks the parent Cells collection for the coordinate under which this cell is currently tracked (getCurrentCoordinate()). If the cell has no parent, or the collection no longer records a current coordinate for it (cell detached, collection emptied or replaced), $coordinate is null and the exception fires. Like the row number, the coordinate string lives in the collection, not in the Cell.
Source
Thrown at src/PhpSpreadsheet/Cell/Cell.php:169
return $parent->getCurrentRow();
}
/**
* Get cell coordinate.
*
* @throws SpreadsheetException
*/
public function getCoordinate(): string
{
$parent = $this->parent;
if ($parent !== null) {
$coordinate = $parent->getCurrentCoordinate();
} else {
$coordinate = null;
}
if ($coordinate === null) {
throw new SpreadsheetException('Coordinate no longer exists');
}
return $coordinate;
}
/**
* Get cell value.
*/
public function getValue(): mixed
{
return $this->value;
}
public function getValueString(): string
{
return StringHelper::convertToString($this->value, false);
}
View on GitHub (pinned to 65b080eef4)
Solutions
- Carry the coordinate string you used to fetch the cell ('B4') through your pipeline instead of the Cell object
- Guard with $cell->getParent() !== null before calling getCoordinate()
- Re-fetch via $sheet->getCell($coord) from a live worksheet when the coordinate is needed again
Example fix
// before
$cells[] = $sheet->getCell('A1');
unset($spreadsheet);
foreach ($cells as $cell) { $coord = $cell->getCoordinate(); } // throws
// after
$coords = ['A1'];
unset($spreadsheet);
// coordinates are plain strings and survive teardown Defensive patterns
Strategy: validation
Validate before calling
$coord = 'B4'; $cell = $sheet->getCell($coord); // ... later, after possible teardown, reuse $coord (plain string) instead of $cell->getCoordinate()
Type guard
function cellHasLiveCoordinate(Cell $cell): bool
{
return $cell->getParent() !== null;
} Try / catch
try {
$coord = $cell->getCoordinate();
} catch (SpreadsheetException $e) {
$coord = $fallbackCoord; // coordinate captured at fetch time
} Prevention
- Treat the coordinate string, not the Cell, as the durable identifier in your data structures
- Re-derive cells from coordinates on a live worksheet each processing stage
- Avoid keeping Cell instances in long-lived caches, queues, or closures
When it happens
Trigger: Calling getCoordinate() on a Cell held after worksheet removal or spreadsheet teardown; on a Cell cloned or re-created outside a collection; after the collection's current-coordinate pointer was reset or the cell was deleted from the collection.
Common situations: Keeping Cell objects in arrays/maps keyed for later writing while sheets get removed or rebuilt; processing cells inside jobs that outlive the spreadsheet instance; debugging sessions where a cell variable is inspected after the workbook was discarded.
Related errors
- Cannot get column when cell is not bound to a worksheet
- Cannot update when cell is not bound to a worksheet
- Cannot get row when cell is not bound to a worksheet
- Cannot check for data validation when cell is not bound to a
- Cannot get data validation for cell that is not bound to a w
AI-assisted analysis of PHPOffice/PhpSpreadsheet@65b080eef4 (2026-08-17).
Data as JSON: /api/errors/6136c49389f6d2a8.
Report an issue: GitHub.