{"record":{"id":"0a86c41333ee3252","repo":"moodle/moodle","slug":"the-table-range-must-be-at-least-1-column-and-row","errorCode":null,"errorMessage":"The table range must be at least 1 column and row","messagePattern":"The table range must be at least 1 column and row","errorType":"exception","errorClass":"PhpSpreadsheetException","httpStatus":null,"severity":"error","filePath":"public/lib/phpspreadsheet/phpspreadsheet/src/PhpSpreadsheet/Worksheet/Table.php","lineNumber":296,"sourceCode":"        // 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        }\n\n        return $this;\n    }\n\n    /**","sourceCodeStart":278,"sourceCodeEnd":314,"githubUrl":"https://github.com/moodle/moodle/blob/48ea8c33227277e916cdd4079dbecef448b37f2c/public/lib/phpspreadsheet/phpspreadsheet/src/PhpSpreadsheet/Worksheet/Table.php#L278-L314","documentation":"Thrown by Table::setRange() (Table.php, around line 296) after the range string has been normalized and parsed via Coordinate::rangeDimension(). It fires when the computed width or height of the range is less than 1, i.e. the range collapses to an empty selection such as a single cell mis-parsed into zero dimension. It is the second stage of range validation: the preceding check ('Table must be set on a range of cells.') already ensured a ':' separator exists; this one ensures the range spans at least one column and one row.","triggerScenarios":"Calling $table->setRange('A1:A1') reversed or an inverted/empty range yielding zero dimension, e.g. setRange('B2:A1')-style ranges that produce zero width/height from rangeDimension().","commonSituations":"Computing the range from an empty data set (no rows/columns to include), off-by-one index math producing zero-width spans, or filtering data before defining the table and ending up with nothing.","solutions":["Ensure the data set is non-empty before computing and assigning the table range.","Fix the range-computation math so width and height are at least 1.","Check Coordinate::rangeDimension($range) results before calling setRange()."],"exampleFix":"// before\n$table->setRange($startCol . '1:' . $endCol . '0'); // endRow 0 when data empty\n// after\nif ($endRow >= 1) {\n    $table->setRange($startCol . '1:' . $endCol . $endRow);\n}","handlingStrategy":"validation","validationCode":"[$w, $h] = \\PhpOffice\\PhpSpreadsheet\\Cell\\Coordinate::rangeDimension($range);\nif ($w < 1 || $h < 1) {\n    throw new InvalidArgumentException(\"Table range has zero dimension: $range\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    $table->setRange($range);\n} catch (\\PhpOffice\\PhpSpreadsheet\\Exception $e) {\n    // skip table creation for empty datasets\n}","preventionTips":["Guard against empty datasets before computing ranges.","Assert row/column counts >= 1 before building the range string.","Log and skip table creation when there is no data instead of forcing a zero-size range."],"tags":["phpspreadsheet","worksheet","range"],"backgroundTag":"value-out-of-range","analyzedSha":"48ea8c33227277e916cdd4079dbecef448b37f2c","analyzedAt":"2026-09-14T20:34:48.527Z","contentChangedAt":"2026-09-14T20:34:48.527Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}