{"record":{"id":"330e7c96729dd266","repo":"PHPOffice/PhpSpreadsheet","slug":"no-table-range-is-defined","errorCode":null,"errorMessage":"No table range is defined.","messagePattern":"No table range is defined\\.","errorType":"exception","errorClass":"PhpOffice\\PhpSpreadsheet\\Exception","httpStatus":null,"severity":"error","filePath":"src/PhpSpreadsheet/Worksheet/Table.php","lineNumber":382,"sourceCode":"     *\n     * @return Table\\Column[]\n     */\n    public function getColumns(): array\n    {\n        return $this->columns;\n    }\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     */","sourceCodeStart":364,"sourceCodeEnd":400,"githubUrl":"https://github.com/PHPOffice/PhpSpreadsheet/blob/65b080eef4d9fd11a5796135ab145883e5c3d6a6/src/PhpSpreadsheet/Worksheet/Table.php#L364-L400","documentation":"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.","triggerScenarios":"$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('').","commonSituations":"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.","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"],"exampleFix":"// before\n$table = new Table();\n$table->setName('Sales');\n$table->setColumn('A'); // throws: range never set\n\n// after\n$table = new Table('A1:E10');\n$table->setName('Sales');\n$table->setColumn('A');","handlingStrategy":"validation","validationCode":"if ($table->getRange() === '') {\n    throw new InvalidArgumentException('Set the table range before configuring columns');\n}\n$table->setColumn('A');","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["phpspreadsheet","table","range","unset-property"],"backgroundTag":"missing-required-configuration","analyzedSha":"65b080eef4d9fd11a5796135ab145883e5c3d6a6","analyzedAt":"2026-08-17T05:40:41.646Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}