PHPOffice/PhpSpreadsheet · error · PhpOffice\PhpSpreadsheet\Exception

Table must be set on a range of cells.

Error message

Table must be set on a range of cells.

What it means

Error "Table must be set on a range of cells." thrown in PHPOffice/PhpSpreadsheet.

Source

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

     *              or passing in an array of [$fromColumnIndex, $fromRow, $toColumnIndex, $toRow] (e.g. [3, 5, 6, 8]),
     *              or an AddressRange object.
     */
    public function setRange(AddressRange|string|array $range = ''): self
    {
        // extract coordinate
        if ($range !== '') {
            [, $range] = Worksheet::extractSheetTitle(Validations::validateCellRange($range), true);
        }
        if (empty($range)) {
            //    Discard all column rules
            $this->columns = [];
            $this->range = '';

            return $this;
        }

        if (!str_contains($range, ':')) {
            throw new PhpSpreadsheetException('Table must be set on a range of cells.');
        }

        [$width, $height] = Coordinate::rangeDimension($range);
        if ($width < 1 || $height < 1) {
            throw new PhpSpreadsheetException('The table range must be at least 1 column and row');
        }

        $this->range = $range;
        $this->autoFilter->setRange($range);

        //    Discard any column rules that are no longer valid within this range
        [$rangeStart, $rangeEnd] = Coordinate::rangeBoundaries($this->range);
        foreach ($this->columns as $key => $value) {
            $colIndex = Coordinate::columnIndexFromString($key);
            if (($rangeStart[0] > $colIndex) || ($rangeEnd[0] < $colIndex)) {
                unset($this->columns[$key]);
            }
        }

View on GitHub (pinned to 65b080eef4)

When it happens

Trigger: Thrown at src/PhpSpreadsheet/Worksheet/Table.php:291 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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