{"record":{"id":"b90368ee99b35b1e","repo":"PHPOffice/PhpSpreadsheet","slug":"outline-level-must-range-between-0-and-7","errorCode":null,"errorMessage":"Outline level must range between 0 and 7.","messagePattern":"Outline level must range between 0 and 7\\.","errorType":"exception","errorClass":"PhpOffice\\PhpSpreadsheet\\Exception","httpStatus":null,"severity":"error","filePath":"src/PhpSpreadsheet/Worksheet/Dimension.php","lineNumber":77,"sourceCode":"\n    /**\n     * Get Outline Level.\n     */\n    public function getOutlineLevel(): int\n    {\n        return $this->outlineLevel;\n    }\n\n    /**\n     * Set Outline Level.\n     * Value must be between 0 and 7.\n     *\n     * @return $this\n     */\n    public function setOutlineLevel(int $level)\n    {\n        if ($level < 0 || $level > 7) {\n            throw new PhpSpreadsheetException('Outline level must range between 0 and 7.');\n        }\n\n        $this->outlineLevel = $level;\n\n        return $this;\n    }\n\n    /**\n     * Get Collapsed.\n     */\n    public function getCollapsed(): bool\n    {\n        return $this->collapsed;\n    }\n\n    /**\n     * Set Collapsed.\n     *","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/PHPOffice/PhpSpreadsheet/blob/65b080eef4d9fd11a5796135ab145883e5c3d6a6/src/PhpSpreadsheet/Worksheet/Dimension.php#L59-L95","documentation":"Excel rows and columns can be grouped into an outline with at most eight levels (0-7); the XLSX format stores only 3 bits for the level. Dimension::setOutlineLevel(), shared by RowDimension and ColumnDimension, enforces that contract and throws for any level below 0 or above 7.","triggerScenarios":"$sheet->getRowDimension(5)->setOutlineLevel(8); $sheet->getColumnDimension('D')->setOutlineLevel(-1); a recursive grouping loop that calls setOutlineLevel($depth) on arbitrarily deep hierarchies without capping the depth.","commonSituations":"Generating outline grouping from unbounded hierarchical data (account trees, WBS structures, nested BOMs); porting code that computes level as $parentLevel + 1 and can exceed 7; passing user-supplied or imported depth values straight through.","solutions":["Clamp the value before setting: setOutlineLevel(max(0, min(7, $level))).","Cap the recursion depth of your grouping logic at 7, or flatten deeper nodes onto level 7.","Validate the 0-7 range where the value enters your code (form, config, import file)."],"exampleFix":"// before\n$sheet->getRowDimension($row)->setOutlineLevel($nodeDepth); // throws when $nodeDepth > 7\n\n// after\n$sheet->getRowDimension($row)->setOutlineLevel(max(0, min(7, $nodeDepth)));","handlingStrategy":"validation","validationCode":"$level = max(0, min(7, (int) $level));\n$sheet->getRowDimension($row)->setOutlineLevel($level);","typeGuard":"function isValidOutlineLevel(int $level): bool\n{\n    return $level >= 0 && $level <= 7;\n}","tryCatchPattern":"try {\n    $dimension->setOutlineLevel($level);\n} catch (PhpSpreadsheetException $e) {\n    $dimension->setOutlineLevel(7); // flatten deepest level onto the Excel ceiling\n}","preventionTips":["Treat 7 as a hard ceiling — the XLSX format stores only 3 bits for the level","Cap the recursion depth of hierarchy-to-outline loops at 7","Validate imported depth values before writing them to dimensions"],"tags":["php","phpspreadsheet","outline","grouping","excel-limits"],"backgroundTag":"value-out-of-range","analyzedSha":"65b080eef4d9fd11a5796135ab145883e5c3d6a6","analyzedAt":"2026-08-17T05:40:41.646Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}