{"record":{"id":"fe66c69f7ddbdd56","repo":"PHPOffice/PhpSpreadsheet","slug":"cell-coordinate-must-not-specify-a-worksheet","errorCode":null,"errorMessage":"Cell coordinate must not specify a worksheet.","messagePattern":"Cell coordinate must not specify a worksheet\\.","errorType":"exception","errorClass":"PhpOffice\\PhpSpreadsheet\\Exception","httpStatus":null,"severity":"error","filePath":"src/PhpSpreadsheet/Worksheet/PageSetup.php","lineNumber":659,"sourceCode":"     *                            When the method is \"O\"verwrite, then a positive integer index will overwrite that indexed\n     *                                entry in the print areas list; a negative index value will identify which entry to\n     *                                overwrite working backward through the print area to the list, with the last entry as -1.\n     *                                Specifying an index value of 0, will overwrite <b>all</b> existing print ranges.\n     *                            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                }","sourceCodeStart":641,"sourceCodeEnd":677,"githubUrl":"https://github.com/PHPOffice/PhpSpreadsheet/blob/65b080eef4d9fd11a5796135ab145883e5c3d6a6/src/PhpSpreadsheet/Worksheet/PageSetup.php#L641-L677","documentation":"setPrintArea() expects a bare range for the current worksheet ('A1:E5' or several comma-separated ranges). An exclamation mark in the value means a sheet-qualified coordinate ('Sheet1!A1:E5') was passed, which the method rejects before doing anything else. The sheet is implied — the PageSetup object already belongs to it.","triggerScenarios":"setPrintArea('Sheet1!A1:E5'); ranges copy-pasted from the formula bar or Name Manager; concatenating $sheet->getTitle() . '!' . $range; reusing strings meant for defined names or print titles.","commonSituations":"Ranges round-tripped through Excel UI or other libraries that always emit sheet-qualified references; code migrated from fluent coordinate builders.","solutions":["Strip the sheet prefix: $value = substr($value, strrpos($value, '!') + 1);","Build print ranges from bare cell coordinates only.","Reject sheet-qualified strings at your input boundary with str_contains($value, '!')."],"exampleFix":"// before\n$sheet->getPageSetup()->setPrintArea('Report!A1:E5');\n\n// after\n$value = 'Report!A1:E5';\n$value = substr($value, strrpos($value, '!') + 1);\n$sheet->getPageSetup()->setPrintArea($value);","handlingStrategy":"validation","validationCode":"if (str_contains($value, '!')) {\n    $value = substr($value, strrpos($value, '!') + 1); // drop the sheet prefix\n}\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":["Pass bare ranges like 'A1:E5' — the sheet is already implied by the PageSetup object","Never concatenate the sheet title into a print-area value","Treat '!' in print-area input as a formatting bug to fix upstream"],"tags":["php","phpspreadsheet","page-setup","print-area","cell-reference"],"backgroundTag":"invalid-cell-reference","analyzedSha":"65b080eef4d9fd11a5796135ab145883e5c3d6a6","analyzedAt":"2026-08-17T05:40:41.646Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}