1 |
efrain |
1 |
# PhpSpreadsheet
|
|
|
2 |
|
|
|
3 |
[](https://github.com/PHPOffice/PhpSpreadsheet/actions)
|
|
|
4 |
[](https://scrutinizer-ci.com/g/PHPOffice/PhpSpreadsheet/?branch=master)
|
|
|
5 |
[](https://scrutinizer-ci.com/g/PHPOffice/PhpSpreadsheet/?branch=master)
|
|
|
6 |
[](https://packagist.org/packages/phpoffice/phpspreadsheet)
|
|
|
7 |
[](https://packagist.org/packages/phpoffice/phpspreadsheet)
|
|
|
8 |
[](https://packagist.org/packages/phpoffice/phpspreadsheet)
|
|
|
9 |
[](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 |
[end of life](https://www.php.net/supported-versions) of that PHP version.
|
|
|
18 |
|
|
|
19 |
Currently the required PHP minimum version is PHP __7.4__, and we [will support that version](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 [composer](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 [CLI vs Application run-time](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 |
- [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 [jpgraph.net](https://jpgraph.net/))
|
|
|
77 |
- [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 [official documentation](https://phpspreadsheet.readthedocs.io). Or check out the [API documentation](https://phpoffice.github.io/PhpSpreadsheet).
|
|
|
95 |
|
|
|
96 |
Please ask your support questions on [StackOverflow](https://stackoverflow.com/questions/tagged/phpspreadsheet), or have a quick chat on [Gitter](https://gitter.im/PHPOffice/PhpSpreadsheet).
|
|
|
97 |
|
|
|
98 |
## Patreon
|
|
|
99 |
|
|
|
100 |
I am now running a [Patreon](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 [an automated tool](/docs/topics/migration-from-PHPExcel.md) for that.
|
|
|
141 |
|
|
|
142 |
## License
|
|
|
143 |
|
|
|
144 |
PhpSpreadsheet is licensed under [MIT](https://github.com/PHPOffice/PhpSpreadsheet/blob/master/LICENSE).
|