{"record":{"id":"1059aff9345722ea","repo":"PHPOffice/PhpSpreadsheet","slug":"value-1059af","errorCode":"#VALUE!","errorMessage":"#VALUE!","messagePattern":"#VALUE!","errorType":"exception","errorClass":"PhpOffice\\PhpSpreadsheet\\Calculation\\Exception","httpStatus":null,"severity":"error","filePath":"src/PhpSpreadsheet/Calculation/DateTimeExcel/Helpers.php","lineNumber":38,"sourceCode":"     */\n    public static function isLeapYear(int|string $year): bool\n    {\n        $year = (int) $year;\n\n        return (($year % 4) === 0) && (($year % 100) !== 0) || (($year % 400) === 0);\n    }\n\n    /**\n     * getDateValue.\n     *\n     * @return float Excel date/time serial value\n     */\n    public static function getDateValue(mixed $dateValue, bool $allowBool = true, ?int $calendar = null): float\n    {\n        if (is_object($dateValue)) {\n            $retval = SharedDateHelper::PHPToExcel($dateValue, calendar: $calendar);\n            if (is_bool($retval)) {\n                throw new Exception(ExcelError::VALUE());\n            }\n\n            return $retval;\n        }\n\n        self::nullFalseTrueToNumber($dateValue, $allowBool, $calendar);\n        if (!is_numeric($dateValue)) {\n            $saveReturnDateType = Functions::getReturnDateType();\n            Functions::setReturnDateType(Functions::RETURNDATE_EXCEL);\n            if (is_string($dateValue)) {\n                $dateValue = DateValue::fromString($dateValue);\n            }\n            Functions::setReturnDateType($saveReturnDateType);\n            if (!is_numeric($dateValue)) {\n                throw new Exception(ExcelError::VALUE());\n            }\n        }\n        if ($dateValue < 0 && Functions::getCompatibilityMode() !== Functions::COMPATIBILITY_OPENOFFICE) {","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/PHPOffice/PhpSpreadsheet/blob/65b080eef4d9fd11a5796135ab145883e5c3d6a6/src/PhpSpreadsheet/Calculation/DateTimeExcel/Helpers.php#L20-L56","documentation":"Sparkline::setLocation() anchors a sparkline in exactly one cell; any argument whose string form contains ':' is treated as a range and rejected before normalization. After stripping '$' markers and any 'Sheet1!' qualifier, the remainder is validated through Coordinate::indexesFromString() (malformed coordinates throw a different Coordinate error). The location is where the sparkline is drawn - its source data range is a separate concept configured elsewhere.","triggerScenarios":"setLocation('A1:A10') - passing the sparkline's data range as its anchor; reusing the same range variable for both data and location; letting a user pick a range for the 'place sparkline at' field.","commonSituations":"Report templates where anchor and data share one variable; UI flows that only offer range pickers; generating many sparklines and accidentally feeding the row range instead of the result cell.","solutions":["Pass a single cell: setLocation('E2')","Derive the anchor from the range's first cell: setLocation(strtok($range, ':'))","Reject range input early with str_contains($value, ':') and a clear message"],"exampleFix":"// before\n$sparkline->setLocation('B2:K2'); // that is the data range -> exception\n\n// after\n$sparkline->setLocation('M2'); // single anchor cell","handlingStrategy":"validation","validationCode":"if (str_contains($location, ':')) {\n    $location = strtok($location, ':'); // anchor = first cell of the range, or reject with a UI error\n}\n$sparkline->setLocation($location);","typeGuard":"function isSingleCellReference(string $ref): bool\n{\n    return !str_contains($ref, ':');\n}","tryCatchPattern":"try {\n    $sparkline->setLocation($userInput);\n} catch (\\PhpOffice\\PhpSpreadsheet\\Exception $e) {\n    // ask the user for one anchor cell, not a range\n}","preventionTips":["Keep the sparkline's data range and its anchor location in separate variables","Offer a single-cell picker (not a range picker) for the location field","Validate early with str_contains($value, ':')"],"tags":["sparkline","cell-reference","range-vs-cell","validation"],"backgroundTag":"invalid-cell-reference","analyzedSha":"65b080eef4d9fd11a5796135ab145883e5c3d6a6","analyzedAt":"2026-08-17T05:40:41.646Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}