{"record":{"id":"5904f562bddaf514","repo":"PHPOffice/PhpSpreadsheet","slug":"invalid-visibility-value","errorCode":null,"errorMessage":"Invalid visibility value.","messagePattern":"Invalid visibility value\\.","errorType":"exception","errorClass":"PhpOffice\\PhpSpreadsheet\\Exception","httpStatus":null,"severity":"error","filePath":"src/PhpSpreadsheet/Spreadsheet.php","lineNumber":1680,"sourceCode":"     *  - 'hidden' (self::VISIBILITY_HIDDEN):\n     *       Workbook window is hidden, but can be shown by the user\n     *       via the user interface\n     *  - 'veryHidden' (self::VISIBILITY_VERY_HIDDEN):\n     *       Workbook window is hidden and cannot be shown in the\n     *       user interface.\n     *\n     * @param null|string $visibility visibility status of the workbook\n     */\n    public function setVisibility(?string $visibility): void\n    {\n        if ($visibility === null) {\n            $visibility = self::VISIBILITY_VISIBLE;\n        }\n\n        if (in_array($visibility, self::WORKBOOK_VIEW_VISIBILITY_VALUES)) {\n            $this->visibility = $visibility;\n        } else {\n            throw new Exception('Invalid visibility value.');\n        }\n    }\n\n    /**\n     * Get 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     * @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     *","sourceCodeStart":1662,"sourceCodeEnd":1698,"githubUrl":"https://github.com/PHPOffice/PhpSpreadsheet/blob/65b080eef4d9fd11a5796135ab145883e5c3d6a6/src/PhpSpreadsheet/Spreadsheet.php#L1662-L1698","documentation":"Spreadsheet::setVisibility(?string) accepts exactly three workbook visibility states — 'visible', 'hidden', 'veryHidden' (the Spreadsheet::VISIBILITY_* constants, mirroring Excel's VBA project/ workbook visibility model). null defaults to 'visible'; anything else throws 'Invalid visibility value.'","triggerScenarios":"setVisibility('Visible') or 'VISIBLE' (wrong case); 'invisible'/'minimized' (made-up states); forwarding raw user/DB strings without validation; copy-pasting 'veryHidden' as 'veryhidden' or 'very-hidden'.","commonSituations":"Config files or DB enum columns whose values drifted from the allowed set; UI dropdowns with labels ('Hidden from users') passed instead of values; code written against another library's vocabulary (e.g. 'minimized') or older docs.","solutions":["Use the constants: $spreadsheet->setVisibility(Spreadsheet::VISIBILITY_VERYHIDDEN);","Whitelist input against Spreadsheet::VISIBILITY_VISIBLE / VISIBILITY_HIDDEN / VISIBILITY_VERYHIDDEN and reject early.","If absence should mean visible, pass null (the setter defaults it) rather than an empty string."],"exampleFix":"// before\n$spreadsheet->setVisibility('very-hidden'); // throws\n\n// after\nuse PhpOffice\\PhpSpreadsheet\\Spreadsheet;\n$spreadsheet->setVisibility(Spreadsheet::VISIBILITY_VERYHIDDEN);","handlingStrategy":"validation","validationCode":"use PhpOffice\\PhpSpreadsheet\\Spreadsheet;\n$allowed = [Spreadsheet::VISIBILITY_VISIBLE, Spreadsheet::VISIBILITY_HIDDEN, Spreadsheet::VISIBILITY_VERYHIDDEN];\nif (!in_array($visibility, $allowed, true)) {\n    throw new \\InvalidArgumentException('visibility must be one of: ' . implode(', ', $allowed));\n}\n$spreadsheet->setVisibility($visibility);","typeGuard":"function isValidVisibility(string $v): bool\n{\n    return in_array($v, [\n        \\PhpOffice\\PhpSpreadsheet\\Spreadsheet::VISIBILITY_VISIBLE,\n        \\PhpOffice\\PhpSpreadsheet\\Spreadsheet::VISIBILITY_HIDDEN,\n        \\PhpOffice\\PhpSpreadsheet\\Spreadsheet::VISIBILITY_VERYHIDDEN,\n    ], true);\n}","tryCatchPattern":"try {\n    $spreadsheet->setVisibility($visibility);\n} catch (\\PhpOffice\\PhpSpreadsheet\\Exception $e) {\n    $spreadsheet->setVisibility(null); // defaults to 'visible'\n}","preventionTips":["Always use the Spreadsheet::VISIBILITY_* constants.","Validate config/DB enum values against the constant set at boot.","Pass null for 'default' rather than invented strings."],"tags":["workbook-view","validation","visibility","enum","phpspreadsheet"],"backgroundTag":"invalid-enum-value","analyzedSha":"65b080eef4d9fd11a5796135ab145883e5c3d6a6","analyzedAt":"2026-08-17T05:40:41.646Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}