PHPOffice/PhpSpreadsheet · error · PhpOffice\PhpSpreadsheet\Exception

A pivot table requires at least one data (value) field

Error message

A pivot table requires at least one data (value) field

What it means

Error "A pivot table requires at least one data (value) field" thrown in PHPOffice/PhpSpreadsheet.

Source

Thrown at src/PhpSpreadsheet/Worksheet/PivotTable/PivotTableBuilder.php:198

        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(): array
    {
        [$start, $end] = Coordinate::rangeBoundaries($this->sourceRange);
        $startColumn = (int) $start[0];
        $endColumn = (int) $end[0];
        $headerRow = (int) $start[1];
        $names = [];
        for ($col = $startColumn; $col <= $endColumn; ++$col) {
            $cell = Coordinate::stringFromColumnIndex($col) . $headerRow;
            $names[] = $this->sourceWorksheet->getCell($cell)->getValueString();
        }

        return $names;

View on GitHub (pinned to 65b080eef4)

When it happens

Trigger: Thrown at src/PhpSpreadsheet/Worksheet/PivotTable/PivotTableBuilder.php:198 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/e783096f3778e2d5. Report an issue: GitHub.