Guide · Open source
How to use PhpSpreadsheet: install, read and write spreadsheets in PHP
Updated · written with AI from the project's own documentation and checked against our catalogue data
PhpSpreadsheet is a PHP library that lets your code read and write spreadsheet files, including Excel and LibreOffice Calc formats. This guide explains what it is, what it needs to run, and how to decide whether it fits your project. It is written for PHP developers who need to generate or import spreadsheets from a web app or script.
Quick start
- 1Check your PHP version. Confirm PHP 8.2 or newer is installed, since that is the stated minimum.
- 2Install Composer. Composer is required to install the package in a PHP project.
- 3Follow the official install guide. Use the Installation section of phpspreadsheet.readthedocs.io for the current install command.
- 4Load a spreadsheet file. Use the classes described in the official documentation to open an Excel or LibreOffice Calc file.
- 5Read or write cells. Access the worksheet data in your code, or write values from your application into a new file.
- 6Migrate older PHPExcel code if needed. Run the automated migration tool linked in the README before updating namespaces.
What PhpSpreadsheet does
PhpSpreadsheet is a library written in pure PHP. It offers a set of classes that allow you to read and write various spreadsheet file formats such as Excel and LibreOffice Calc.
Because it is pure PHP, it does not need Excel or other office software installed on the server. It is the successor to PHPExcel, which is no longer maintained.
- Read spreadsheet files into your PHP code
- Write spreadsheet files from data produced by your application
- Works in web apps and command-line scripts that run PHP
What you need before installing
The required PHP minimum is PHP 8.2. The README says support for that version is planned until 30 June 2027. Check the composer.json file in the repository for other requirements.
The package is installed with Composer, the PHP dependency manager. The README points to the official documentation for the exact install steps.
- PHP 8.2 or newer
- Composer
Install PhpSpreadsheet
The README links to the install instructions in the official documentation rather than showing a Composer command directly. Follow the Installation section at phpspreadsheet.readthedocs.io for the current command.
If you want the source code itself, the README shows a git clone of the GitHub repository. Use that when you are working on the library or reading its code, not as a substitute for the documented install.
- Read the Installation section of the official documentation
- Confirm your PHP version is 8.2 or newer before you start
git clone https://github.com/PHPOffice/PhpSpreadsheetRead and write spreadsheet files
The README describes PhpSpreadsheet as a set of classes for reading and writing spreadsheet formats. The official documentation at phpspreadsheet.readthedocs.io contains the code examples for loading a file, reading cells and saving output, so use it as the reference for exact method names.
The author's Patreon posts cover topics such as iterating rows and cells, and how Excel handles dates and number formats. These are described in the README as supporter articles, and some will later move into the public documentation.
- Use the official documentation for read and write examples
- Look at the README's planned topics such as tables, charts and conditional formatting to see what is covered later
Migrating from PHPExcel
PhpSpreadsheet is the next version of PHPExcel. It breaks compatibility to improve the code base (namespaces, PSR compliance and newer PHP language features). PHPExcel is no longer maintained, so new work should target PhpSpreadsheet.
The README links to an automated migration tool, documented in the project's migration-from-PHPExcel topic file.
- Expect breaking changes because the namespaces and classes were reworked
- Use the automated migration tool linked in the README for older PHPExcel code
Where to get help
The README asks support questions to be posted on StackOverflow under the phpspreadsheet tag, or to be discussed on Gitter. The API documentation is published separately at phpoffice.github.io/PhpSpreadsheet.
- Official docs: phpspreadsheet.readthedocs.io
- API reference: phpoffice.github.io/PhpSpreadsheet
- Questions: StackOverflow tag phpspreadsheet
What people use it for
- Generating an Excel report from database rows in a web app
- Importing a customer-supplied spreadsheet into a PHP backend
- Producing scheduled export files from a PHP script
- Moving an older PHPExcel project to a maintained library
Frequently asked questions
What does PhpSpreadsheet require to run?
The README states that the required PHP minimum is PHP 8.2. It is installed with Composer, and the composer.json file lists other requirements.
Is PhpSpreadsheet free to use?
PhpSpreadsheet is licensed under the MIT licence, as stated in the README. You can find the full licence text in the LICENSE file on the GitHub repository.
Do I need Excel installed on the server?
No. The library is written in pure PHP, so it does not need Excel or other office software installed on the server.
What is the difference between PHPExcel and PhpSpreadsheet?
PhpSpreadsheet is the next version of PHPExcel and breaks compatibility to improve the code base. PHPExcel is no longer maintained, so new work should use PhpSpreadsheet.
What are alternatives to PhpSpreadsheet?
The project lists PHPExcel, Spout and SimpleXLSX as comparable projects. PHPExcel is the predecessor, so Spout and SimpleXLSX are the other options to evaluate for your use case.
Can I use PhpSpreadsheet in a non-PHP project?
No. The library only runs in PHP, so it is not a fit for projects written in other languages. For desktop editing by hand, a desktop office program is a better choice.
New agent skills, repos and AI tools — every week
The best new skills and open-source projects, the fastest-growing repos, and one free prompt. Five minutes to read. Unsubscribe anytime.
Our verdict
PhpSpreadsheet suits PHP developers who need to generate or import Excel and LibreOffice Calc files from code, and teams moving off PHPExcel. It is not a good choice for people who just want to edit a spreadsheet by hand, for non-PHP projects, or for projects on PHP versions below 8.2.
Install options & downloads