{"record":{"id":"5a1f48ea38d1c45e","repo":"PHPOffice/PhpSpreadsheet","slug":"tab-ratio-must-be-between-0-and-1000","errorCode":null,"errorMessage":"Tab ratio must be between 0 and 1000.","messagePattern":"Tab ratio must be between 0 and 1000\\.","errorType":"exception","errorClass":"PhpOffice\\PhpSpreadsheet\\Exception","httpStatus":null,"severity":"error","filePath":"src/PhpSpreadsheet/Spreadsheet.php","lineNumber":1706,"sourceCode":"     * @return int Ratio between the workbook tabs bar and the horizontal scroll bar\n     */\n    public function getTabRatio(): int\n    {\n        return $this->tabRatio;\n    }\n\n    /**\n     * Set the ratio between the workbook tabs bar and the horizontal scroll bar\n     * TabRatio is assumed to be out of 1000 of the horizontal window width.\n     *\n     * @param int $tabRatio Ratio between the tabs bar and the horizontal scroll bar\n     */\n    public function setTabRatio(int $tabRatio): void\n    {\n        if ($tabRatio >= 0 && $tabRatio <= 1000) {\n            $this->tabRatio = (int) $tabRatio;\n        } else {\n            throw new Exception('Tab ratio must be between 0 and 1000.');\n        }\n    }\n\n    public function reevaluateAutoFilters(bool $resetToMax): void\n    {\n        foreach ($this->workSheetCollection as $sheet) {\n            $filter = $sheet->getAutoFilter();\n            if (!empty($filter->getRange())) {\n                if ($resetToMax) {\n                    $filter->setRangeToMaxRow();\n                }\n                $filter->showHideRows();\n            }\n        }\n    }\n\n    /**\n     * @throws Exception","sourceCodeStart":1688,"sourceCodeEnd":1724,"githubUrl":"https://github.com/PHPOffice/PhpSpreadsheet/blob/65b080eef4d9fd11a5796135ab145883e5c3d6a6/src/PhpSpreadsheet/Spreadsheet.php#L1688-L1724","documentation":"Spreadsheet::setTabRatio(int) sets the ratio of the sheet-tab bar to the horizontal scroll bar, expressed out of 1000 (it maps to Excel's tabRatio workbook-view property). Only values in the closed range 0..1000 are accepted; anything outside throws 'Tab ratio must be between 0 and 1000.'","triggerScenarios":"setTabRatio(100) meaning '100%' then later passing a 0-1 float cast to int (0); setTabRatio(1200); accepting a percentage from user input (0-100 scale) without rescaling to 0-1000; arithmetic that can go negative.","commonSituations":"Confusion between percent (0-100) and Excel's per-mille scale (0-1000); UI sliders that emit 0-100 directly; config values inherited from another library using a different scale.","solutions":["Rescale percentages: setTabRatio((int) round($percent * 10));","Clamp before calling: $ratio = max(0, min(1000, $ratio));","Validate config/UI input against the 0..1000 range and reject early with a clear message."],"exampleFix":"// before\n$spreadsheet->setTabRatio(60); // meant 60% but throws nothing... wrong scale\n$spreadsheet->setTabRatio(1500); // throws\n\n// after\n$percent = 60;\n$spreadsheet->setTabRatio(max(0, min(1000, (int) round($percent * 10)))); // 600 = 60%","handlingStrategy":"validation","validationCode":"$ratio = max(0, min(1000, (int) $ratio)); // clamp to 0..1000\n$spreadsheet->setTabRatio($ratio);","typeGuard":"function isValidTabRatio(int $r): bool\n{\n    return $r >= 0 && $r <= 1000;\n}","tryCatchPattern":"try {\n    $spreadsheet->setTabRatio($ratio);\n} catch (\\PhpOffice\\PhpSpreadsheet\\Exception $e) {\n    $spreadsheet->setTabRatio(600); // 60%, a safe default\n}","preventionTips":["The scale is 0..1000 (per-mille), not 0..100 percent.","Rescale percentages with *10 before calling.","Clamp UI/config values at the boundary."],"tags":["workbook-view","validation","tab-ratio","range","phpspreadsheet"],"backgroundTag":"value-out-of-range","analyzedSha":"65b080eef4d9fd11a5796135ab145883e5c3d6a6","analyzedAt":"2026-08-17T05:40:41.646Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}