PHPOffice/PhpSpreadsheet · error · PhpOffice\PhpSpreadsheet\Exception

Column is outside of current table range.

Error message

Column is outside of current table range.

What it means

Thrown by Table::isColumnInRange() when the supplied column letter converts to a column index that falls before the range start or after the range end (Coordinate::columnIndexFromString vs Coordinate::rangeBoundaries). The library is telling you the column you are configuring is not one of the columns the table spans.

Source

Thrown at src/PhpSpreadsheet/Worksheet/Table.php:388

    }

    /**
     * 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
     */
    public function getColumnOffset(string $column): int
    {
        return $this->isColumnInRange($column);
    }

    /**

View on GitHub (pinned to 65b080eef4)

Solutions

  1. Widen the table range first: $table->setRange('A1:F10') so the column is inside
  2. Use a column that actually lies within the current range (getRange() shows the boundaries)
  3. Compute allowed letters from the range: [$start, $end] = Coordinate::rangeBoundaries($table->getRange()); then only pass letters between columnIndexToString($start[0]) and columnIndexToString($end[0])

Example fix

// before
$table = new Table('A1:E10');
$table->setColumn('F'); // throws: F is outside A:E

// after
$table = new Table('A1:F10');
$table->setColumn('F');
Defensive patterns

Strategy: validation

Validate before calling

use PhpOffice\PhpSpreadsheet\Cell\Coordinate;

function columnWithinTable(Table $table, string $column): bool
{
    $index = Coordinate::columnIndexFromString($column);
    [$start, $end] = Coordinate::rangeBoundaries($table->getRange());

    return $index >= $start[0] && $index <= $end[0];
}

if (columnWithinTable($table, 'F')) {
    $table->setColumn('F');
}

Prevention

When it happens

Trigger: $table->setColumn('F') while the range is 'A1:E10'; calling isColumnInRange('A') on a table whose range starts at 'C'; computing column letters from spreadsheet coordinates instead of table-relative offsets after the range was shrunk.

Common situations: Off-by-one when generating letters for wide tables; shrinking a table's range with setRange() after columns beyond the new edge were already configured; mixing absolute sheet columns with table-relative positions.

Related errors


AI-assisted analysis of PHPOffice/PhpSpreadsheet@65b080eef4 (2026-08-17). Data as JSON: /api/errors/24eb99425232ffdd. Report an issue: GitHub.