PHPOffice/PhpSpreadsheet · error · PhpOffice\PhpSpreadsheet\Exception
Cell coordinate must not be absolute.
Error message
Cell coordinate must not be absolute.
What it means
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.
Source
Thrown at src/PhpSpreadsheet/Worksheet/PageSetup.php:663
* When the method is "I"nsert, then a positive index will insert after that indexed entry in
* the print areas list, while a negative index will insert before the indexed entry.
* Specifying an index value of 0, will always append the new print range at the end of the
* list.
* Print areas are numbered from 1
* @param string $method Determines the method used when setting multiple print areas
* Default behaviour, or the "O" method, overwrites existing print area
* The "I" method, inserts the new print area before any specified index, or at the end of the list
*
* @return $this
*/
public function setPrintArea(string $value, int $index = 0, string $method = self::SETPRINTRANGE_OVERWRITE): static
{
if (str_contains($value, '!')) {
throw new PhpSpreadsheetException('Cell coordinate must not specify a worksheet.');
} elseif (!str_contains($value, ':')) {
throw new PhpSpreadsheetException('Cell coordinate must be a range of cells.');
} elseif (str_contains($value, '$')) {
throw new PhpSpreadsheetException('Cell coordinate must not be absolute.');
}
$value = strtoupper($value);
if (!$this->printArea) {
$index = 0;
}
if ($method == self::SETPRINTRANGE_OVERWRITE) {
if ($index == 0) {
$this->printArea = $value;
} else {
$printAreas = explode(',', (string) $this->printArea);
if ($index < 0) {
$index = count($printAreas) - abs($index) + 1;
}
if (($index <= 0) || ($index > count($printAreas))) {
throw new PhpSpreadsheetException('Invalid index for setting print range.');
}
$printAreas[$index - 1] = $value;View on GitHub (pinned to 65b080eef4)
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.
Example fix
// before
$sheet->getPageSetup()->setPrintArea('$B$2:$F$20');
// after
$sheet->getPageSetup()->setPrintArea(str_replace('$', '', '$B$2:$F$20')); Defensive patterns
Strategy: validation
Validate before calling
$value = str_replace('$', '', $value); // strip absolute markers
$sheet->getPageSetup()->setPrintArea($value); Type guard
function isBareCellRange(string $value): bool
{
return !str_contains($value, '!') && str_contains($value, ':') && !str_contains($value, '$');
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: Ranges copied from formulas or documentation; coordinates produced by other spreadsheet libraries in A1-absolute style; mixed user input.
Related errors
- Requested Print Area does not exist
- Cell coordinate must not specify a worksheet.
- Cell coordinate must be a range of cells.
- Invalid index for setting print range.
- Invalid method for setting print range.
AI-assisted analysis of PHPOffice/PhpSpreadsheet@65b080eef4 (2026-08-17).
Data as JSON: /api/errors/d0e88268d616da11.
Report an issue: GitHub.