PHPOffice/PhpSpreadsheet · error · PhpOffice\PhpSpreadsheet\Exception
No table range is defined.
Error message
No table range is defined.
What it means
Thrown by Table::isColumnInRange() when the table's range property is empty. Column operations (setColumn, and any code computing a column's offset) need the defined range to resolve boundaries, so a Table that never had setRange() called cannot answer column questions and fails fast instead of returning a meaningless offset.
Source
Thrown at src/PhpSpreadsheet/Worksheet/Table.php:382
*
* @return Table\Column[]
*/
public function getColumns(): array
{
return $this->columns;
}
/**
* Validate that the specified column is in the Table range.
*
* @param string $column Column name (e.g. A)
*
* @return int The column offset within the table range
*/
public function isColumnInRange(string $column): int
{
if (empty($this->range)) {
throw new PhpSpreadsheetException('No table range is defined.');
}
$columnIndex = Coordinate::columnIndexFromString($column);
[$rangeStart, $rangeEnd] = Coordinate::rangeBoundaries($this->range);
if (($rangeStart[0] > $columnIndex) || ($rangeEnd[0] < $columnIndex)) {
throw new PhpSpreadsheetException('Column is outside of current table range.');
}
return $columnIndex - $rangeStart[0];
}
/**
* Get a specified Table Column Offset within the defined Table range.
*
* @param string $column Column name (e.g. A)
*
* @return int The offset of the specified column within the table range
*/View on GitHub (pinned to 65b080eef4)
Solutions
- Call $table->setRange('A1:E10') (headers row + data) before any setColumn()/isColumnInRange() call
- Or construct with the range upfront: new Table('A1:E10')
- Guard with if ($table->getRange() === '') before column operations
Example fix
// before
$table = new Table();
$table->setName('Sales');
$table->setColumn('A'); // throws: range never set
// after
$table = new Table('A1:E10');
$table->setName('Sales');
$table->setColumn('A'); Defensive patterns
Strategy: validation
Validate before calling
if ($table->getRange() === '') {
throw new InvalidArgumentException('Set the table range before configuring columns');
}
$table->setColumn('A'); Prevention
- Prefer new Table('A1:E10') so a range exists from construction
- Treat range as a required constructor argument in your own wrappers
- Assert getRange() !== '' in table-building helpers before column work
When it happens
Trigger: $table = new Table(); $table->setColumn('A'); — setColumn calls isColumnInRange while $this->range is ''. Also any direct call to isColumnInRange() on a table constructed without a range (new Table('A1:E10') would have set one) or after setRange('').
Common situations: Building a table step-by-step (new Table, setName, setColumn...) and forgetting setRange() before the first column call; passing '' to setRange() from a variable computed from headers that came back empty.
Related errors
- #VALUE!
- #VALUE!
- Cell coordinate string can not be a range of cells
- Range does not contain any information
- Each array entry must be an array
AI-assisted analysis of PHPOffice/PhpSpreadsheet@65b080eef4 (2026-08-17).
Data as JSON: /api/errors/330e7c96729dd266.
Report an issue: GitHub.