PHPOffice/PhpSpreadsheet · error · PhpOffice\PhpSpreadsheet\Exception
Pivot source field '{$fieldName}' does not exist in range {$
Error message
Pivot source field '{$fieldName}' does not exist in range {$this->sourceRange} What it means
Error "Pivot source field '{$fieldName}' does not exist in range {$this->sourceRange}" thrown in PHPOffice/PhpSpreadsheet.
Source
Thrown at src/PhpSpreadsheet/Worksheet/PivotTable/PivotTableBuilder.php:186
}
$targetWorksheet->addPivotTable($pivotTable);
return $pivotTable;
}
private function place(string $fieldName, string $axis, ?string $subtotal, ?string $caption): self
{
$this->assertFieldExists($fieldName);
$this->placements[$fieldName] = ['axis' => $axis, 'subtotal' => $subtotal, 'caption' => $caption];
return $this;
}
private function assertFieldExists(string $fieldName): void
{
if (!in_array($fieldName, $this->fieldNames, true)) {
throw new PhpSpreadsheetException("Pivot source field '{$fieldName}' does not exist in range {$this->sourceRange}");
}
}
private function assertHasDataField(): void
{
foreach ($this->placements as $placement) {
if ($placement['axis'] === PivotField::AXIS_VALUES) {
return;
}
}
throw new PhpSpreadsheetException('A pivot table requires at least one data (value) field');
}
/**
* @return string[]
*/
private function readHeaderNames(): arrayView on GitHub (pinned to 65b080eef4)
When it happens
Trigger: Thrown at src/PhpSpreadsheet/Worksheet/PivotTable/PivotTableBuilder.php:186 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of PHPOffice/PhpSpreadsheet@65b080eef4 (2026-08-17).
Data as JSON: /api/errors/ff6d51ee9094c8d2.
Report an issue: GitHub.