{"record":{"id":"d0e88268d616da11","repo":"PHPOffice/PhpSpreadsheet","slug":"cell-coordinate-must-not-be-absolute","errorCode":null,"errorMessage":"Cell coordinate must not be absolute.","messagePattern":"Cell coordinate must not be absolute\\.","errorType":"exception","errorClass":"PhpOffice\\PhpSpreadsheet\\Exception","httpStatus":null,"severity":"error","filePath":"src/PhpSpreadsheet/Worksheet/PageSetup.php","lineNumber":663,"sourceCode":"     *                            When the method is \"I\"nsert, then a positive index will insert after that indexed entry in\n     *                                the print areas list, while a negative index will insert before the indexed entry.\n     *                                Specifying an index value of 0, will always append the new print range at the end of the\n     *                                list.\n     *                            Print areas are numbered from 1\n     * @param string $method Determines the method used when setting multiple print areas\n     *                            Default behaviour, or the \"O\" method, overwrites existing print area\n     *                            The \"I\" method, inserts the new print area before any specified index, or at the end of the list\n     *\n     * @return $this\n     */\n    public function setPrintArea(string $value, int $index = 0, string $method = self::SETPRINTRANGE_OVERWRITE): static\n    {\n        if (str_contains($value, '!')) {\n            throw new PhpSpreadsheetException('Cell coordinate must not specify a worksheet.');\n        } elseif (!str_contains($value, ':')) {\n            throw new PhpSpreadsheetException('Cell coordinate must be a range of cells.');\n        } elseif (str_contains($value, '$')) {\n            throw new PhpSpreadsheetException('Cell coordinate must not be absolute.');\n        }\n        $value = strtoupper($value);\n        if (!$this->printArea) {\n            $index = 0;\n        }\n\n        if ($method == self::SETPRINTRANGE_OVERWRITE) {\n            if ($index == 0) {\n                $this->printArea = $value;\n            } else {\n                $printAreas = explode(',', (string) $this->printArea);\n                if ($index < 0) {\n                    $index = count($printAreas) - abs($index) + 1;\n                }\n                if (($index <= 0) || ($index > count($printAreas))) {\n                    throw new PhpSpreadsheetException('Invalid index for setting print range.');\n                }\n                $printAreas[$index - 1] = $value;","sourceCodeStart":645,"sourceCodeEnd":681,"githubUrl":"https://github.com/PHPOffice/PhpSpreadsheet/blob/65b080eef4d9fd11a5796135ab145883e5c3d6a6/src/PhpSpreadsheet/Worksheet/PageSetup.php#L645-L681","documentation":"setPrintArea() rejects absolute references: any dollar sign in the value throws 'Cell coordinate must not be absolute.' Print areas are stored relative to the sheet, so '$A$1:$E$5' — exactly what Excel's formula bar shows for an absolute range — must be normalized to 'A1:E5' first.","triggerScenarios":"setPrintArea('$B$2:$F$20') pasted from a formula; ranges emitted by tools that default to absolute notation; partially absolute forms like '$A1:A5' also fail.","commonSituations":"Ranges copied from formulas or documentation; coordinates produced by other spreadsheet libraries in A1-absolute style; mixed user input.","solutions":["Normalize before setting: $value = str_replace('$', '', $value);","Generate ranges from plain coordinates instead of reusing formula fragments.","Treat '$' in a print-area value as an input error at your validation boundary."],"exampleFix":"// before\n$sheet->getPageSetup()->setPrintArea('$B$2:$F$20');\n\n// after\n$sheet->getPageSetup()->setPrintArea(str_replace('$', '', '$B$2:$F$20'));","handlingStrategy":"validation","validationCode":"$value = str_replace('$', '', $value); // strip absolute markers\n$sheet->getPageSetup()->setPrintArea($value);","typeGuard":"function isBareCellRange(string $value): bool\n{\n    return !str_contains($value, '!') && str_contains($value, ':') && !str_contains($value, '$');\n}","tryCatchPattern":null,"preventionTips":["Normalize ranges pasted from formulas with str_replace('$', '', $value)","Print areas are stored relative — build them from plain coordinates","Reject '$' in print-area input at your validation boundary"],"tags":["php","phpspreadsheet","page-setup","print-area","absolute-reference"],"backgroundTag":"invalid-cell-reference","analyzedSha":"65b080eef4d9fd11a5796135ab145883e5c3d6a6","analyzedAt":"2026-08-17T05:40:41.646Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}