PhpSpreadsheet
Read, write, and manipulate Excel, CSV, and ODS spreadsheet files in pure PHP with no external office suite required.
Repository Health
Technical Analysis
PhpSpreadsheet is a pure PHP library for reading, writing, and manipulating spreadsheet files across formats including XLSX, XLS, ODS, CSV, Gnumeric, and SYLK. It exposes an in-memory object model — worksheets, cells, styles, charts, and formulas — that mirrors how desktop spreadsheet applications represent data, so applications can build reports, generate exports, or parse uploaded spreadsheets without shelling out to Excel or LibreOffice.
Originally created as the successor to the discontinued PHPExcel project, PhpSpreadsheet rebuilt the library around namespaces, PSR compliance, and modern PHP practices while keeping the same broad format coverage. It ships a calculation engine that evaluates hundreds of Excel formula functions, a flexible IOFactory for auto-detecting file types, and writer support for PDF export via Dompdf, Mpdf, or TCPDF.
What You Get
- A
Spreadsheetobject model with worksheets, cells, styles, rich text, charts, comments, and defined names - Readers and writers for XLSX, XLS, ODS, CSV, Gnumeric, SYLK, HTML, and XML formats via a single
IOFactory - A formula calculation engine supporting hundreds of Excel functions across math, date/time, financial, statistical, and text categories
- PDF export writers that integrate with Dompdf, Mpdf, or TCPDF
- Fluent, chainable APIs for styling, formatting, and manipulating cells and worksheets
Common Use Cases
- Generating downloadable Excel reports from application data (invoices, financial summaries, exports)
- Importing user-uploaded spreadsheets to bulk-load records into a database
- Building admin dashboards that let users export filtered data tables as XLSX or CSV
- Converting spreadsheets to PDF for printable reports
Under The Hood
Architecture — PhpSpreadsheet centers on an in-memory Spreadsheet object model (src/PhpSpreadsheet/Spreadsheet.php) composed of Worksheet, Cell, Style, Chart, and RichText sub-models that are fully decoupled from any file format. Persistence is handled by pluggable Reader\IReader and Writer\IWriter implementations, one namespace per format (Reader\Xlsx, Reader\Xls, Reader\Ods, Reader\Gnumeric, etc.), each with format-specific parsing logic — the Xlsx reader unzips and parses OOXML, while Xls implements the legacy binary BIFF format directly. IOFactory (src/PhpSpreadsheet/IOFactory.php) auto-detects a file’s format by extension and a canRead() probe, and exposes registerReader/registerWriter so consumers can add custom formats without modifying the library. A separate Calculation subsystem (src/PhpSpreadsheet/Calculation/Calculation.php plus per-category function folders like DateTimeExcel, Financial, Engineering) implements its own formula tokenizer/parser/evaluator, letting formulas be recalculated purely in PHP. The result is a clean read → model → calculate → write pipeline where every stage is independently swappable.
Tech Stack — Pure PHP 8.2+, with composer.json requiring a long list of core extensions (ext-zip, ext-xml, ext-gd, ext-dom, ext-mbstring, etc.) needed to parse ZIP-based OOXML/ODS containers, render embedded images, and handle multi-byte text. Runtime dependencies are deliberately minimal: markbaker/complex and markbaker/matrix back the complex-number and matrix math used by financial/engineering formula functions, maennchen/zipstream-php streams ZIP writes for xlsx/ods output without buffering the whole file in memory, and psr/simple-cache provides an optional caching interface. PDF export is delegated to whichever of Dompdf, Mpdf, or TCPDF the consuming application already has installed, rather than bundling one. Development tooling includes PHPUnit 10/11, PHPStan at level 10 (the strictest setting, with a small tracked baseline), and both PHP-CS-Fixer and PHP_CodeSniffer (including a PHPCompatibility ruleset) to enforce style and PHP-version compatibility.
Code Quality — The repository ships 1,214 dedicated PHPUnit test files (tests/PhpSpreadsheetTests/) covering readers, writers, styles, and individual formula functions, plus a tests/Benchmark suite for performance-sensitive paths like streaming XLSX reads. Static analysis runs at PHPStan level 10 — the tool’s maximum strictness — with violations tracked in a small, actively-shrinking phpstan-baseline.neon rather than suppressed wholesale. Core classes like Cell use typed properties, explicit nullable/mixed typing, and dedicated Exception classes per subsystem (Calculation\Exception, Reader\Exception, Writer\Exception) rather than generic exceptions, making failure modes easy to catch narrowly. A .php-cs-fixer.dist.php config with over a dozen configured rule sets and a CI-enforced composer check script (phpcs, PHPCompatibility, php-cs-fixer, phpstan, phpunit) keep style and typing consistent across 415 contributors.
API Design — The public API favors fluent, chainable method calls (e.g. $spreadsheet->getProperties()->setCreator(...)->setTitle(...)), documented explicitly in the official architecture guide, while still allowing a plain imperative style for consumers who prefer it. IOFactory::load() gives a one-line entry point that auto-detects file type, while explicit IOFactory::createReader()/createWriter() calls remain available when the format is already known or non-standard. Constants like IOFactory::READER_XLSX and WRITER_ODS centralize format identifiers instead of scattering magic strings. The tradeoff is surface area: full mastery of styling, conditional formatting, and the 300+ formula functions requires digging through extensive docs, but the entry-level workflow — IOFactory::load($file), read cells, IOFactory::createWriter($spreadsheet, 'Xlsx')->save($out) — is only a few lines.
Used by 7 apps in this directory
Craft CMS
CMS
A developer-first PHP CMS with clean-slate content modeling, auto-generated GraphQL API, and a four-tier edition system that scales from solo projects to enterprise deployments.
EspoCRM
Marketing · Ecommerce · CRM
Open-source CRM platform with metadata-driven customization, field-level permissions, and a full REST API — deploy on your own infrastructure.
Fleetbase
Logistics
Modular open-source logistics and supply chain operating system
Invoice Ninja
Invoicing Finance · Project Management
Self-hostable invoicing, time-tracking, and multi-gateway payment platform for freelancers and small businesses, with built-in e-invoicing compliance for EU and global standards.
Kimai
Invoicing Finance · Project Management
Professional open-source time tracking with invoicing, multi-user support, SAML/LDAP auth, and a full REST API—self-host it or use the cloud.
LimeSurvey
Forms Surveys
The world's most flexible open-source survey platform with 900+ templates, conditional logic, 80+ languages, and full GDPR compliance for any scale.
Mautic
Automation · Marketing · Ecommerce
The world's largest open source marketing automation platform — own your data, run multi-channel campaigns, and escape vendor lock-in forever.