| 1 |
# PhpSpreadsheet |
| 2 |
|
| 3 |
[](https://github.com/PHPOffice/PhpSpreadsheet/actions](https://github.com/PHPOffice/PhpSpreadsheet/actions](https://github.com/PHPOffice/PhpSpreadsheet/actions) |
| 4 |
[](https://scrutinizer-ci.com/g/PHPOffice/PhpSpreadsheet/?branch=master](https://scrutinizer-ci.com/g/PHPOffice/PhpSpreadsheet/?branch=master](https://scrutinizer-ci.com/g/PHPOffice/PhpSpreadsheet/?branch=master) |
| 5 |
[](https://scrutinizer-ci.com/g/PHPOffice/PhpSpreadsheet/?branch=master](https://scrutinizer-ci.com/g/PHPOffice/PhpSpreadsheet/?branch=master](https://scrutinizer-ci.com/g/PHPOffice/PhpSpreadsheet/?branch=master) |
| 6 |
[](https://packagist.org/packages/phpoffice/phpspreadsheet](https://packagist.org/packages/phpoffice/phpspreadsheet](https://packagist.org/packages/phpoffice/phpspreadsheet) |
| 7 |
[](https://packagist.org/packages/phpoffice/phpspreadsheet](https://packagist.org/packages/phpoffice/phpspreadsheet](https://packagist.org/packages/phpoffice/phpspreadsheet) |
| 8 |
[](https://packagist.org/packages/phpoffice/phpspreadsheet](https://packagist.org/packages/phpoffice/phpspreadsheet](https://packagist.org/packages/phpoffice/phpspreadsheet) |
| 9 |
[](https://gitter.im/PHPOffice/PhpSpreadsheet](https://gitter.im/PHPOffice/PhpSpreadsheet](https://gitter.im/PHPOffice/PhpSpreadsheet) |
| 10 |
|
| 11 |
PhpSpreadsheet is a library written in pure PHP and offers a set of classes that |
| 12 |
allow you to read and write various spreadsheet file formats such as Excel and LibreOffice Calc. |
| 13 |
|
| 14 |
## PHP Version Support |
| 15 |
|
| 16 |
LTS: Support for PHP versions will only be maintained for a period of six months beyond the |
| 17 |
[](https://www.php.net/supported-versionsend of life](https://www.php.net/supported-versions](https://www.php.net/supported-versions) of that PHP version. |
| 18 |
|
| 19 |
Currently the required PHP minimum version is PHP __7.4__, and we [](https://www.php.net/eol.phpwill support that version](https://www.php.net/eol.php](https://www.php.net/eol.php) until 28th June 2023. |
| 20 |
|
| 21 |
See the `composer.json` for other requirements. |
| 22 |
|
| 23 |
## Installation |
| 24 |
|
| 25 |
Use [](https://getcomposer.orgcomposer](https://getcomposer.org](https://getcomposer.org) to install PhpSpreadsheet into your project: |
| 26 |
|
| 27 |
```sh |
| 28 |
composer require phpoffice/phpspreadsheet |
| 29 |
``` |
| 30 |
|
| 31 |
If you are building your installation on a development machine that is on a different PHP version to the server where it will be deployed, or if your PHP CLI version is not the same as your run-time such as `php-fpm` or Apache's `mod_php`, then you might want to add the following to your `composer.json` before installing: |
| 32 |
```json |
| 33 |
{ |
| 34 |
"require": { |
| 35 |
"phpoffice/phpspreadsheet": "^1.28" |
| 36 |
}, |
| 37 |
"config": { |
| 38 |
"platform": { |
| 39 |
"php": "7.4" |
| 40 |
} |
| 41 |
} |
| 42 |
} |
| 43 |
``` |
| 44 |
and then run |
| 45 |
```sh |
| 46 |
composer install |
| 47 |
``` |
| 48 |
to ensure that the correct dependencies are retrieved to match your deployment environment. |
| 49 |
|
| 50 |
See [](https://php.watch/articles/composer-platform-checkCLI vs Application run-time](https://php.watch/articles/composer-platform-check](https://php.watch/articles/composer-platform-check) for more details. |
| 51 |
|
| 52 |
### Additional Installation Options |
| 53 |
|
| 54 |
If you want to write to PDF, or to include Charts when you write to HTML or PDF, then you will need to install additional libraries: |
| 55 |
|
| 56 |
#### PDF |
| 57 |
|
| 58 |
For PDF Generation, you can install any of the following, and then configure PhpSpreadsheet to indicate which library you are going to use: |
| 59 |
- mpdf/mpdf |
| 60 |
- dompdf/dompdf |
| 61 |
- tecnickcom/tcpdf |
| 62 |
|
| 63 |
and configure PhpSpreadsheet using: |
| 64 |
|
| 65 |
```php |
| 66 |
// Dompdf, Mpdf or Tcpdf (as appropriate) |
| 67 |
$className = \PhpOffice\PhpSpreadsheet\Writer\Pdf\Dompdf::class; |
| 68 |
IOFactory::registerWriter('Pdf', $className); |
| 69 |
``` |
| 70 |
or the appropriate PDF Writer wrapper for the library that you have chosen to install. |
| 71 |
|
| 72 |
#### Chart Export |
| 73 |
|
| 74 |
For Chart export, we support following packages, which you will also need to install yourself using `composer require` |
| 75 |
- [](https://packagist.org/packages/jpgraph/jpgraphjpgraph/jpgraph](https://packagist.org/packages/jpgraph/jpgraph](https://packagist.org/packages/jpgraph/jpgraph) (this package was abandoned at version 4.0. |
| 76 |
You can manually download the latest version that supports PHP 8 and above from [](https://jpgraph.net/jpgraph.net](https://jpgraph.net/](https://jpgraph.net/)) |
| 77 |
- [](https://packagist.org/packages/mitoteam/jpgraphmitoteam/jpgraph](https://packagist.org/packages/mitoteam/jpgraph](https://packagist.org/packages/mitoteam/jpgraph) - up to date fork with modern PHP versions support and some bugs fixed. |
| 78 |
|
| 79 |
and then configure PhpSpreadsheet using: |
| 80 |
```php |
| 81 |
// to use jpgraph/jpgraph |
| 82 |
Settings::setChartRenderer(\PhpOffice\PhpSpreadsheet\Chart\Renderer\JpGraph::class); |
| 83 |
//or |
| 84 |
// to use mitoteam/jpgraph |
| 85 |
Settings::setChartRenderer(\PhpOffice\PhpSpreadsheet\Chart\Renderer\MtJpGraphRenderer::class); |
| 86 |
``` |
| 87 |
|
| 88 |
One or the other of these libraries is necessary if you want to generate HTML or PDF files that include charts; or to render a Chart to an Image format from within your code. |
| 89 |
They are not necessary to define charts for writing to `Xlsx` files. |
| 90 |
Other file formats don't support writing Charts. |
| 91 |
|
| 92 |
## Documentation |
| 93 |
|
| 94 |
Read more about it, including install instructions, in the [](https://phpspreadsheet.readthedocs.ioofficial documentation](https://phpspreadsheet.readthedocs.io](https://phpspreadsheet.readthedocs.io). Or check out the [](https://phpoffice.github.io/PhpSpreadsheetAPI documentation](https://phpoffice.github.io/PhpSpreadsheet](https://phpoffice.github.io/PhpSpreadsheet). |
| 95 |
|
| 96 |
Please ask your support questions on [](https://stackoverflow.com/questions/tagged/phpspreadsheetStackOverflow](https://stackoverflow.com/questions/tagged/phpspreadsheet](https://stackoverflow.com/questions/tagged/phpspreadsheet), or have a quick chat on [](https://gitter.im/PHPOffice/PhpSpreadsheetGitter](https://gitter.im/PHPOffice/PhpSpreadsheet](https://gitter.im/PHPOffice/PhpSpreadsheet). |
| 97 |
|
| 98 |
## Patreon |
| 99 |
|
| 100 |
I am now running a [](https://www.patreon.com/MarkBakerPatreon](https://www.patreon.com/MarkBaker](https://www.patreon.com/MarkBaker) to support the work that I do on PhpSpreadsheet. |
| 101 |
|
| 102 |
Supporters will receive access to articles about working with PhpSpreadsheet, and how to use some of its more advanced features. |
| 103 |
|
| 104 |
Posts already available to Patreon supporters: |
| 105 |
- The Dating Game |
| 106 |
- A look at how MS Excel (and PhpSpreadsheet) handle date and time values. |
| 107 |
- Looping the Loop |
| 108 |
- Advice on Iterating through the rows and cells in a worksheet. |
| 109 |
|
| 110 |
And for Patrons at levels actively using PhpSpreadsheet: |
| 111 |
- Behind the Mask |
| 112 |
- A look at Number Format Masks. |
| 113 |
|
| 114 |
The Next Article (currently Work in Progress): |
| 115 |
- Formula for Success |
| 116 |
- How to debug formulae that don't produce the expected result. |
| 117 |
|
| 118 |
|
| 119 |
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. |
| 120 |
|
| 121 |
Planned posts for the future include topics like: |
| 122 |
- Tables |
| 123 |
- Structured References |
| 124 |
- AutoFiltering |
| 125 |
- Array Formulae |
| 126 |
- Conditional Formatting |
| 127 |
- Data Validation |
| 128 |
- Value Binders |
| 129 |
- Images |
| 130 |
- Charts |
| 131 |
|
| 132 |
After a period of six months exclusive to Patreon supporters, articles will be incorporated into the public documentation for the library. |
| 133 |
|
| 134 |
## PHPExcel vs PhpSpreadsheet ? |
| 135 |
|
| 136 |
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.). |
| 137 |
|
| 138 |
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. |
| 139 |
|
| 140 |
Do you need to migrate? There is [](/docs/topics/migration-from-PHPExcel.mdan automated tool](/docs/topics/migration-from-PHPExcel.md](/docs/topics/migration-from-PHPExcel.md) for that. |
| 141 |
|
| 142 |
## License |
| 143 |
|
| 144 |
PhpSpreadsheet is licensed under [](https://github.com/PHPOffice/PhpSpreadsheet/blob/master/LICENSEMIT](https://github.com/PHPOffice/PhpSpreadsheet/blob/master/LICENSE](https://github.com/PHPOffice/PhpSpreadsheet/blob/master/LICENSE). |
| 145 |
|