{"record":{"id":"24eb99425232ffdd","repo":"PHPOffice/PhpSpreadsheet","slug":"column-is-outside-of-current-table-range","errorCode":null,"errorMessage":"Column is outside of current table range.","messagePattern":"Column is outside of current table range\\.","errorType":"exception","errorClass":"PhpOffice\\PhpSpreadsheet\\Exception","httpStatus":null,"severity":"error","filePath":"src/PhpSpreadsheet/Worksheet/Table.php","lineNumber":388,"sourceCode":"    }\n\n    /**\n     * Validate that the specified column is in the Table range.\n     *\n     * @param string $column Column name (e.g. A)\n     *\n     * @return int The column offset within the table range\n     */\n    public function isColumnInRange(string $column): int\n    {\n        if (empty($this->range)) {\n            throw new PhpSpreadsheetException('No table range is defined.');\n        }\n\n        $columnIndex = Coordinate::columnIndexFromString($column);\n        [$rangeStart, $rangeEnd] = Coordinate::rangeBoundaries($this->range);\n        if (($rangeStart[0] > $columnIndex) || ($rangeEnd[0] < $columnIndex)) {\n            throw new PhpSpreadsheetException('Column is outside of current table range.');\n        }\n\n        return $columnIndex - $rangeStart[0];\n    }\n\n    /**\n     * Get a specified Table Column Offset within the defined Table range.\n     *\n     * @param string $column Column name (e.g. A)\n     *\n     * @return int The offset of the specified column within the table range\n     */\n    public function getColumnOffset(string $column): int\n    {\n        return $this->isColumnInRange($column);\n    }\n\n    /**","sourceCodeStart":370,"sourceCodeEnd":406,"githubUrl":"https://github.com/PHPOffice/PhpSpreadsheet/blob/65b080eef4d9fd11a5796135ab145883e5c3d6a6/src/PhpSpreadsheet/Worksheet/Table.php#L370-L406","documentation":"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.","triggerScenarios":"$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.","commonSituations":"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.","solutions":["Widen the table range first: $table->setRange('A1:F10') so the column is inside","Use a column that actually lies within the current range (getRange() shows the boundaries)","Compute allowed letters from the range: [$start, $end] = Coordinate::rangeBoundaries($table->getRange()); then only pass letters between columnIndexToString($start[0]) and columnIndexToString($end[0])"],"exampleFix":"// before\n$table = new Table('A1:E10');\n$table->setColumn('F'); // throws: F is outside A:E\n\n// after\n$table = new Table('A1:F10');\n$table->setColumn('F');","handlingStrategy":"validation","validationCode":"use PhpOffice\\PhpSpreadsheet\\Cell\\Coordinate;\n\nfunction columnWithinTable(Table $table, string $column): bool\n{\n    $index = Coordinate::columnIndexFromString($column);\n    [$start, $end] = Coordinate::rangeBoundaries($table->getRange());\n\n    return $index >= $start[0] && $index <= $end[0];\n}\n\nif (columnWithinTable($table, 'F')) {\n    $table->setColumn('F');\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Derive column letters from the table's own boundaries via Coordinate::rangeBoundaries()","After changing a table's range, drop or re-check previously configured columns","Log the table range alongside the failing column when reports fail"],"tags":["phpspreadsheet","table","column","out-of-range","bounds-check"],"backgroundTag":"index-out-of-bounds","analyzedSha":"65b080eef4d9fd11a5796135ab145883e5c3d6a6","analyzedAt":"2026-08-17T05:40:41.646Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}