{"record":{"id":"d35f0fb98f3be29e","repo":"PHPOffice/PhpSpreadsheet","slug":"value-d35f0f","errorCode":"#VALUE!","errorMessage":"#VALUE!","messagePattern":"#VALUE!","errorType":"exception","errorClass":"PhpOffice\\PhpSpreadsheet\\Calculation\\Exception","httpStatus":null,"severity":"error","filePath":"src/PhpSpreadsheet/Calculation/DateTimeExcel/Week.php","lineNumber":195,"sourceCode":"                $DoW = self::dow0Becomes7($DoW);\n\n                break;\n            case 3:\n                $DoW = self::dow0Becomes7($DoW) - 1;\n\n                break;\n        }\n\n        return $DoW;\n    }\n\n    /**\n     * @param mixed $style expect int\n     */\n    private static function validateStyle(mixed $style): int\n    {\n        if (!is_numeric($style)) {\n            throw new Exception(ExcelError::VALUE());\n        }\n        $style = (int) $style;\n        if (($style < 1) || ($style > 3)) {\n            throw new Exception(ExcelError::NAN());\n        }\n\n        return $style;\n    }\n\n    private static function dow0Becomes7(int $DoW): int\n    {\n        return ($DoW === 0) ? 7 : $DoW;\n    }\n\n    /**\n     * @param mixed $dateValue Excel date serial value (float), PHP date timestamp (integer),\n     *                                    PHP DateTime object, or a standard date string\n     */","sourceCodeStart":177,"sourceCodeEnd":213,"githubUrl":"https://github.com/PHPOffice/PhpSpreadsheet/blob/65b080eef4d9fd11a5796135ab145883e5c3d6a6/src/PhpSpreadsheet/Calculation/DateTimeExcel/Week.php#L177-L213","documentation":"Table::setRange() computes the range's dimensions with Coordinate::rangeDimension() (end minus start plus 1) and throws if width or height is under 1. Any well-formed ascending range yields at least 1 in each dimension, so in practice this fires for reversed/inverted ranges such as 'E10:A1' where the arithmetic goes negative - it is essentially a defensive guard against degenerate range strings.","triggerScenarios":"setRange('E10:A1') - the 'from' corner right of or below the 'to' corner; ranges assembled from two independently chosen cells without ordering (drag-select inverted, min/max not applied).","commonSituations":"Ranges composed from unordered user selections; importers trusting foreign range strings; corner variables swapped during refactoring.","solutions":["Order the corners ascending before composing the range string (sort column indexes and row numbers)","Build the range from min/max of the two coordinates' indexes","Reject reversed ranges at the input layer with a clear message"],"exampleFix":"// before\n$table->setRange('E10:A1'); // inverted corners -> exception\n\n// after\nuse PhpOffice\\PhpSpreadsheet\\Cell\\Coordinate;\n[$s, $e] = Coordinate::rangeBoundaries('E10:A1');\n$from = Coordinate::stringFromColumnIndex(min($s[0], $e[0])) . min($s[1], $e[1]);\n$to = Coordinate::stringFromColumnIndex(max($s[0], $e[0])) . max($s[1], $e[1]);\n$table->setRange($from . ':' . $to); // 'A1:E10'","handlingStrategy":"validation","validationCode":"use PhpOffice\\PhpSpreadsheet\\Cell\\Coordinate;\n\nfunction normalizeRange(string $a, string $b): string\n{\n    [$s, $e] = Coordinate::rangeBoundaries($a . ':' . $b);\n    $from = Coordinate::stringFromColumnIndex(min($s[0], $e[0])) . min($s[1], $e[1]);\n    $to = Coordinate::stringFromColumnIndex(max($s[0], $e[0])) . max($s[1], $e[1]);\n\n    return $from . ':' . $to;\n}\n\n$table->setRange(normalizeRange($cell1, $cell2));","typeGuard":null,"tryCatchPattern":"try {\n    $table->setRange($range);\n} catch (\\PhpOffice\\PhpSpreadsheet\\Exception $e) {\n    // inverted or degenerate range; normalize corners and retry\n}","preventionTips":["Always order range corners ascending (sort column index and row number) before building the string","Do not trust range strings from user selections or foreign files without normalizing","A valid ascending range can never trigger this check - it guards degenerate input"],"tags":["table","range","inverted-range","dimension"],"backgroundTag":"invalid-range-format","analyzedSha":"65b080eef4d9fd11a5796135ab145883e5c3d6a6","analyzedAt":"2026-08-17T05:40:41.646Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}