{"record":{"id":"65c6f3b39946d615","repo":"PHPOffice/PhpSpreadsheet","slug":"cell-coordinate-must-be-a-range-of-cells","errorCode":null,"errorMessage":"Cell coordinate must be a range of cells.","messagePattern":"Cell coordinate must be a range of cells\\.","errorType":"exception","errorClass":"PhpOffice\\PhpSpreadsheet\\Exception","httpStatus":null,"severity":"error","filePath":"src/PhpSpreadsheet/Worksheet/PageSetup.php","lineNumber":661,"sourceCode":"     *                                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                }\n                if (($index <= 0) || ($index > count($printAreas))) {\n                    throw new PhpSpreadsheetException('Invalid index for setting print range.');","sourceCodeStart":643,"sourceCodeEnd":679,"githubUrl":"https://github.com/PHPOffice/PhpSpreadsheet/blob/65b080eef4d9fd11a5796135ab145883e5c3d6a6/src/PhpSpreadsheet/Worksheet/PageSetup.php#L643-L679","documentation":"setPrintArea() validates that the value contains a colon, i.e. is a range rather than a single cell. Passing 'A1' (or any malformed string without ':') throws 'Cell coordinate must be a range of cells.' To print a single cell you must spell it as the degenerate range 'A1:A1'.","triggerScenarios":"setPrintArea('A1'); a dynamically built range where start equals end and the colon got dropped; typos like 'A1..E5' or 'A1;E5'; feeding a cell coordinate where a range is required.","commonSituations":"Print areas computed from data extents that collapse to one cell; coordinates obtained from getCoordinate()-style APIs passed to setPrintArea; separators localized by spreadsheet UIs.","solutions":["Pass 'A1:A1' when you genuinely want a single cell.","Always assemble ranges as $start . ':' . $end in your code.","Validate with str_contains($value, ':') before calling."],"exampleFix":"// before\n$sheet->getPageSetup()->setPrintArea('A1');\n\n// after\n$sheet->getPageSetup()->setPrintArea('A1:A1');","handlingStrategy":"validation","validationCode":"if (!str_contains($value, ':')) {\n    $value = $value . ':' . $value; // single cell -> degenerate range 'A1:A1'\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":["A single cell must be spelled 'A1:A1'","Assemble ranges in code as $start . ':' . $end, never from loose fragments","Check str_contains($value, ':') before calling setPrintArea()"],"tags":["php","phpspreadsheet","page-setup","print-area","range-validation"],"backgroundTag":"invalid-cell-reference","analyzedSha":"65b080eef4d9fd11a5796135ab145883e5c3d6a6","analyzedAt":"2026-08-17T05:40:41.646Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}