{"record":{"id":"e9a3bd5e76109a23","repo":"PHPOffice/PhpSpreadsheet","slug":"table-must-be-set-on-a-range-of-cells","errorCode":null,"errorMessage":"Table must be set on a range of cells.","messagePattern":"Table must be set on a range of cells\\.","errorType":"exception","errorClass":"PhpOffice\\PhpSpreadsheet\\Exception","httpStatus":null,"severity":"error","filePath":"src/PhpSpreadsheet/Worksheet/Table.php","lineNumber":291,"sourceCode":"     *              or passing in an array of [$fromColumnIndex, $fromRow, $toColumnIndex, $toRow] (e.g. [3, 5, 6, 8]),\n     *              or an AddressRange object.\n     */\n    public function setRange(AddressRange|string|array $range = ''): self\n    {\n        // extract coordinate\n        if ($range !== '') {\n            [, $range] = Worksheet::extractSheetTitle(Validations::validateCellRange($range), true);\n        }\n        if (empty($range)) {\n            //    Discard all column rules\n            $this->columns = [];\n            $this->range = '';\n\n            return $this;\n        }\n\n        if (!str_contains($range, ':')) {\n            throw new PhpSpreadsheetException('Table must be set on a range of cells.');\n        }\n\n        [$width, $height] = Coordinate::rangeDimension($range);\n        if ($width < 1 || $height < 1) {\n            throw new PhpSpreadsheetException('The table range must be at least 1 column and row');\n        }\n\n        $this->range = $range;\n        $this->autoFilter->setRange($range);\n\n        //    Discard any column rules that are no longer valid within this range\n        [$rangeStart, $rangeEnd] = Coordinate::rangeBoundaries($this->range);\n        foreach ($this->columns as $key => $value) {\n            $colIndex = Coordinate::columnIndexFromString($key);\n            if (($rangeStart[0] > $colIndex) || ($rangeEnd[0] < $colIndex)) {\n                unset($this->columns[$key]);\n            }\n        }","sourceCodeStart":273,"sourceCodeEnd":309,"githubUrl":"https://github.com/PHPOffice/PhpSpreadsheet/blob/65b080eef4d9fd11a5796135ab145883e5c3d6a6/src/PhpSpreadsheet/Worksheet/Table.php#L273-L309","documentation":"Error \"Table must be set on a range of cells.\" thrown in PHPOffice/PhpSpreadsheet.","triggerScenarios":"Thrown at src/PhpSpreadsheet/Worksheet/Table.php:291 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"65b080eef4d9fd11a5796135ab145883e5c3d6a6","analyzedAt":"2026-08-17T05:40:41.646Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}