# Pivot Table Support in Excel Templates

**Last Updated:** 2025-11-20

## Overview

Pivot tables are powerful Excel features for data analysis, but PhpSpreadsheet does not have native pivot table generation support. Pivot tables must be added manually in Excel after template generation.

## Current Implementation

### Template Definition

Pivot tables can be documented in template JSON files, but they require manual creation:

```json
{
  "sheets": [
    {
      "name": "Pivot Analysis",
      "pivot_tables": [
        {
          "name": "Umsatz nach Monat",
          "source_range": "Data!A1:D100",
          "position": "F1",
          "rows": ["Monat"],
          "columns": ["Produkt"],
          "values": [
            {
              "field": "Umsatz",
              "function": "sum"
            }
          ]
        }
      ]
    }
  ]
}
```

## Manual Pivot Table Creation

After generating an Excel template, pivot tables can be added manually:

1. Open the generated Excel file
2. Select the data range for the pivot table
3. Insert → PivotTable
4. Configure rows, columns, and values
5. Apply formatting to match Ordio branding
6. Position pivot table according to definition

## Pivot Table Best Practices

1. **Data Preparation:** Ensure source data is clean and structured
2. **Naming:** Use descriptive German names for pivot tables
3. **Formatting:** Apply Ordio brand colors and styles
4. **Positioning:** Place pivot tables after source data
5. **Refresh:** Set up automatic refresh if data changes

## Future Enhancement

If PhpSpreadsheet adds pivot table support or a compatible extension becomes available, pivot table generation can be automated.

## Limitations

- Pivot tables are not automatically generated
- Manual creation required in Excel
- Dynamic updates require manual refresh or VBA
- Complex pivot table configurations require Excel expertise

## Workaround

For templates requiring pivot tables:

1. Generate template with source data
2. Create pivot tables manually in Excel
3. Save as template file (.xltx)
4. Distribute template file instead of regenerating
