Adds the ability to create a new pivot table from a range of source data, building on the existing read model and round-trip preservation. New Worksheet\PivotTable\PivotTableBuilder provides a fluent API: point it at a source worksheet and range (its first row supplies the field names), place fields on the row/column axes and add value fields with an aggregation function, then build() produces a PivotTable and registers it on a target sheet. Source field names are resolved from the header row (RichText/inline string headers included), and distinct values are collected for the cache definition's sharedItems. The model gains what generation needs: PivotTable::isGenerated(), per-field data-field captions, subtotal-function constants on PivotField, and sharedItems on PivotCacheDefinition. Writer: a new Writer\Xlsx\PivotTable generates the pivotTableDefinition, pivotCacheDefinition (with refreshOnLoad set) and an empty pivotCacheRecords part, plus their rels. On save, generated pivot tables are assigned indices that continue past any preserved pivot parts (so a workbook can mix loaded and new pivots without collision) and are wired into the worksheet relationships, workbook <pivotCaches> registry, workbook relationships and content types via the same unparsed-data path used for preservation. Values are computed by the spreadsheet application on open via refresh-on-load, so we don't reimplement the aggregation engine. Output is a structurally consistent OPC package and reads back into the object model. Tests cover building, validation errors, the generated parts and wiring, aggregation attributes, and mixing preserved with generated pivots.
PhpSpreadsheet
PhpSpreadsheet is a library written in pure PHP and offers a set of classes that allow you to read and write various spreadsheet file formats such as Excel and LibreOffice Calc.
This is the master branch, and is maintained for security and bug fixes.
PHP Version Support
LTS: For maintained branches, support for PHP versions will only be maintained for a period of six months beyond the end of life of that PHP version. Dropping support for versions after that date will not be considered a breaking change.
Currently the required PHP minimum version is PHP 8.2, and we will support that version until 30th June 2027.
See the composer.json for other requirements.
Installation
See the install instructions.
Documentation
Read more about it, including install instructions, in the official documentation. Or check out the API documentation.
Please ask your support questions on StackOverflow, or have a quick chat on Gitter.
Patreon
I am now running a Patreon to support the work that I do on PhpSpreadsheet.
Supporters will receive access to articles about working with PhpSpreadsheet, and how to use some of its more advanced features.
Posts already available to Patreon supporters:
- The Dating Game
- A look at how MS Excel (and PhpSpreadsheet) handle date and time values.
- Looping the Loop
- Advice on Iterating through the rows and cells in a worksheet.
And for Patrons at levels actively using PhpSpreadsheet:
- Behind the Mask
- A look at Number Format Masks.
The Next Article (currently Work in Progress):
- Formula for Success
- How to debug formulae that don't produce the expected result.
My aim is to post at least one article each month, taking a detailed look at some feature of MS Excel and how to use that feature in PhpSpreadsheet, or on how to perform different activities in PhpSpreadsheet.
Planned posts for the future include topics like:
- Tables
- Structured References
- AutoFiltering
- Array Formulae
- Conditional Formatting
- Data Validation
- Value Binders
- Images
- Charts
After a period of six months exclusive to Patreon supporters, articles will be incorporated into the public documentation for the library.
PHPExcel vs PhpSpreadsheet ?
PhpSpreadsheet is the next version of PHPExcel. It breaks compatibility to dramatically improve the code base quality (namespaces, PSR compliance, use of latest PHP language features, etc.).
Because all efforts have shifted to PhpSpreadsheet, PHPExcel will no longer be maintained. All contributions for PHPExcel, patches and new features, should target PhpSpreadsheet master branch.
Do you need to migrate? There is an automated tool for that.
License
PhpSpreadsheet is licensed under MIT.