{"record":{"id":"8baa1352ee698e5a","repo":"PHPOffice/PhpSpreadsheet","slug":"num-8baa13","errorCode":"#NUM!","errorMessage":"#NUM!","messagePattern":"#NUM!","errorType":"error_code","errorClass":"PhpOffice\\PhpSpreadsheet\\Calculation\\Exception","httpStatus":null,"severity":"error","filePath":"src/PhpSpreadsheet/Calculation/DateTimeExcel/Difference.php","lineNumber":74,"sourceCode":"\n        $PHPDiffDateObject = $PHPEndDateObject->diff($PHPStartDateObject);\n\n        $retVal = false;\n        $retVal = self::replaceRetValue($retVal, $unit, 'D') ?? self::datedifD($difference);\n        $retVal = self::replaceRetValue($retVal, $unit, 'M') ?? self::datedifM($PHPDiffDateObject);\n        $retVal = self::replaceRetValue($retVal, $unit, 'MD') ?? self::datedifMD($startDays, $endDays, $PHPEndDateObject, $PHPDiffDateObject);\n        $retVal = self::replaceRetValue($retVal, $unit, 'Y') ?? self::datedifY($PHPDiffDateObject);\n        $retVal = self::replaceRetValue($retVal, $unit, 'YD') ?? self::datedifYD($difference, $startYears, $endYears, $PHPStartDateObject, $PHPEndDateObject);\n        $retVal = self::replaceRetValue($retVal, $unit, 'YM') ?? self::datedifYM($PHPDiffDateObject);\n\n        return is_bool($retVal) ? ExcelError::VALUE() : $retVal;\n    }\n\n    private static function initialDiff(float $startDate, float $endDate): float\n    {\n        // Validate parameters\n        if ($startDate > $endDate) {\n            throw new Exception(ExcelError::NAN());\n        }\n\n        return $endDate - $startDate;\n    }\n\n    /**\n     * Decide whether it's time to set retVal.\n     */\n    private static function replaceRetValue(bool|int $retVal, string $unit, string $compare): null|bool|int\n    {\n        if ($retVal !== false || $unit !== $compare) {\n            return $retVal;\n        }\n\n        return null;\n    }\n\n    private static function datedifD(float $difference): int","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/PHPOffice/PhpSpreadsheet/blob/65b080eef4d9fd11a5796135ab145883e5c3d6a6/src/PhpSpreadsheet/Calculation/DateTimeExcel/Difference.php#L56-L92","documentation":"SheetView::setView() accepts exactly three layout types - SheetView::SHEETVIEW_NORMAL ('normal'), SHEETVIEW_PAGE_LAYOUT ('pageLayout'), SHEETVIEW_PAGE_BREAK_PREVIEW ('pageBreakPreview') - or null, which is normalized to 'normal'. Anything else throws 'Invalid sheetview layout type.' because the values must match the OOXML sheetView view attribute. The match is exact, so casing and spelling matter.","triggerScenarios":"setView('PageLayout') (wrong case), setView('pagebreakpreview'), setView('page_break_preview'), or forwarding a view name produced by another library, a config file, or a legacy PHPExcel codebase into this setter.","commonSituations":"Hardcoded strings instead of the class constants; user- or config-supplied view names; uppercase or underscore variants that 'look right' but are not the exact OOXML token.","solutions":["Use the constants: setView(SheetView::SHEETVIEW_PAGE_BREAK_PREVIEW)","Map/whitelist external values to the three constants before calling","Pass null when you want the default normal view"],"exampleFix":"// before\n$sheet->getSheetView()->setView('PageLayout'); // wrong case -> exception\n\n// after\nuse PhpOffice\\PhpSpreadsheet\\Worksheet\\SheetView;\n$sheet->getSheetView()->setView(SheetView::SHEETVIEW_PAGE_LAYOUT);","handlingStrategy":"type-guard","validationCode":"$allowed = [SheetView::SHEETVIEW_NORMAL, SheetView::SHEETVIEW_PAGE_LAYOUT, SheetView::SHEETVIEW_PAGE_BREAK_PREVIEW];\n$viewType = in_array($candidate, $allowed, true) ? $candidate : null; // null -> normal\n$sheet->getSheetView()->setView($viewType);","typeGuard":"function isValidSheetViewType(?string $type): bool\n{\n    return in_array($type, ['normal', 'pageLayout', 'pageBreakPreview'], true);\n}","tryCatchPattern":"try {\n    $sheet->getSheetView()->setView($viewType);\n} catch (\\PhpOffice\\PhpSpreadsheet\\Exception $e) {\n    $sheet->getSheetView()->setView(null); // default to normal\n}","preventionTips":["Always use the SheetView::SHEETVIEW_* constants, never string literals","Whitelist config/user input against the three constants before calling setView","The comparison is case-sensitive: 'PageLayout' is invalid"],"tags":["sheet-view","enum","invalid-value","case-sensitive"],"backgroundTag":"invalid-enum-value","analyzedSha":"65b080eef4d9fd11a5796135ab145883e5c3d6a6","analyzedAt":"2026-08-17T05:40:41.646Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}