2016-12-03 15:00:54 +00:00
|
|
|
# Welcome to PhpSpreadsheet's documentation
|
2016-11-27 10:34:17 +00:00
|
|
|
|
|
|
|
![Logo](./assets/logo.svg)
|
|
|
|
|
2016-12-03 15:00:54 +00:00
|
|
|
PhpSpreadsheet is a library written in pure PHP and providing a set of
|
|
|
|
classes that allow you to read from and to write to different
|
|
|
|
spreadsheet file formats, like Excel and LibreOffice Calc.
|
2016-11-27 10:34:17 +00:00
|
|
|
|
2017-07-30 14:22:28 +00:00
|
|
|
## File formats supported
|
|
|
|
|
|
|
|
|Format |Reading|Writing|
|
|
|
|
|--------------------------------------------|:-----:|:-----:|
|
|
|
|
|Open Document Format/OASIS (.ods) | ✓ | ✓ |
|
|
|
|
|Office Open XML (.xlsx) Excel 2007 and above| ✓ | ✓ |
|
|
|
|
|BIFF 8 (.xls) Excel 97 and above | ✓ | ✓ |
|
|
|
|
|BIFF 5 (.xls) Excel 95 | ✓ | |
|
|
|
|
|SpreadsheetML (.xml) Excel 2003 | ✓ | |
|
|
|
|
|Gnumeric | ✓ | |
|
|
|
|
|HTML | ✓ | ✓ |
|
|
|
|
|SYLK | ✓ | |
|
|
|
|
|CSV | ✓ | ✓ |
|
2017-10-21 16:54:14 +00:00
|
|
|
|PDF (using either the TCPDF, Dompdf or mPDF libraries, which need to be installed separately)| | ✓ |
|
2017-07-30 14:22:28 +00:00
|
|
|
|
2016-12-03 13:16:45 +00:00
|
|
|
# Getting started
|
|
|
|
|
|
|
|
## Software requirements
|
|
|
|
|
2020-04-27 09:42:32 +00:00
|
|
|
PHP version 7.2 or newer to develop using PhpSpreadsheet. Other requirements, such as PHP extensions, are enforced by
|
2019-07-25 06:12:45 +00:00
|
|
|
composer. See the `require` section of [the composer.json file](https://github.com/PHPOffice/PhpSpreadsheet/blob/master/composer.json)
|
|
|
|
for details.
|
2016-12-03 13:16:45 +00:00
|
|
|
|
2017-07-30 14:22:28 +00:00
|
|
|
### PHP version support
|
|
|
|
|
2020-04-27 09:42:32 +00:00
|
|
|
Support for PHP versions will only be maintained for a period of six months beyond the
|
|
|
|
[end of life of that PHP version](https://www.php.net/eol.php).
|
2017-07-30 14:22:28 +00:00
|
|
|
|
2017-03-13 02:33:02 +00:00
|
|
|
## Installation
|
2016-12-03 13:16:45 +00:00
|
|
|
|
2018-10-23 11:26:25 +00:00
|
|
|
Use [composer](https://getcomposer.org) to install PhpSpreadsheet into your project:
|
2016-12-03 13:16:45 +00:00
|
|
|
|
2017-03-13 02:33:02 +00:00
|
|
|
```sh
|
|
|
|
composer require phpoffice/phpspreadsheet
|
2016-12-03 13:16:45 +00:00
|
|
|
```
|
|
|
|
|
2020-03-24 10:52:22 +00:00
|
|
|
Or also download the documentation and samples if you plan to use them:
|
|
|
|
|
|
|
|
```sh
|
|
|
|
composer require phpoffice/phpspreadsheet --prefer-source
|
|
|
|
```
|
|
|
|
|
|
|
|
|
2017-03-13 02:33:02 +00:00
|
|
|
## Hello World
|
2016-12-03 13:16:45 +00:00
|
|
|
|
2017-03-13 02:33:02 +00:00
|
|
|
This would be the simplest way to write a spreadsheet:
|
2016-12-03 13:16:45 +00:00
|
|
|
|
2017-03-13 02:33:02 +00:00
|
|
|
```php
|
2016-12-03 13:16:45 +00:00
|
|
|
<?php
|
|
|
|
|
2017-03-13 02:33:02 +00:00
|
|
|
require 'vendor/autoload.php';
|
2016-12-03 13:16:45 +00:00
|
|
|
|
2017-03-13 02:33:02 +00:00
|
|
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
|
|
|
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
|
2016-12-03 13:16:45 +00:00
|
|
|
|
2017-03-13 02:33:02 +00:00
|
|
|
$spreadsheet = new Spreadsheet();
|
|
|
|
$sheet = $spreadsheet->getActiveSheet();
|
|
|
|
$sheet->setCellValue('A1', 'Hello World !');
|
2016-12-03 13:16:45 +00:00
|
|
|
|
2017-03-13 02:33:02 +00:00
|
|
|
$writer = new Xlsx($spreadsheet);
|
|
|
|
$writer->save('hello world.xlsx');
|
2016-12-03 13:16:45 +00:00
|
|
|
```
|
|
|
|
|
2017-03-13 02:33:02 +00:00
|
|
|
## Learn by example
|
2016-12-03 13:16:45 +00:00
|
|
|
|
2020-03-24 10:52:22 +00:00
|
|
|
A good way to get started is to run some of the samples. Don't forget to download them via `--prefer-source` composer
|
|
|
|
flag. And then serve them via PHP built-in webserver:
|
2016-12-03 13:16:45 +00:00
|
|
|
|
2017-03-13 02:33:02 +00:00
|
|
|
```sh
|
|
|
|
php -S localhost:8000 -t vendor/phpoffice/phpspreadsheet/samples
|
2016-12-03 13:16:45 +00:00
|
|
|
```
|
|
|
|
|
2017-03-13 02:33:02 +00:00
|
|
|
Then point your browser to:
|
2016-12-03 13:16:45 +00:00
|
|
|
|
2017-03-13 02:33:02 +00:00
|
|
|
> http://localhost:8000/
|
2016-12-03 13:16:45 +00:00
|
|
|
|
2017-03-13 02:33:02 +00:00
|
|
|
The samples may also be run directly from the command line, for example:
|
2016-12-03 13:16:45 +00:00
|
|
|
|
2017-03-13 02:33:02 +00:00
|
|
|
```sh
|
2018-03-09 08:41:43 +00:00
|
|
|
php vendor/phpoffice/phpspreadsheet/samples/Basic/01_Simple.php
|
2016-12-03 13:16:45 +00:00
|
|
|
```
|
|
|
|
|
2017-03-13 02:33:02 +00:00
|
|
|
## Learn by documentation
|
2016-12-03 13:16:45 +00:00
|
|
|
|
2017-03-13 02:33:02 +00:00
|
|
|
For more in-depth documentation, you may read about an [overview of the
|
|
|
|
architecture](./topics/architecture.md),
|
|
|
|
[creating a spreadsheet](./topics/creating-spreadsheet.md),
|
|
|
|
[worksheets](./topics/worksheets.md),
|
|
|
|
[accessing cells](./topics/accessing-cells.md) and
|
|
|
|
[reading and writing to files](./topics/reading-and-writing-to-file.md).
|
2016-12-03 13:16:45 +00:00
|
|
|
|
2020-04-05 08:46:03 +00:00
|
|
|
Or browse the [API documentation](https://phpoffice.github.io/PhpSpreadsheet).
|
2018-06-04 05:23:10 +00:00
|
|
|
|
2016-12-03 13:16:45 +00:00
|
|
|
# Credits
|
|
|
|
|
2017-03-13 02:33:02 +00:00
|
|
|
Please refer to the [contributor
|
2016-12-03 15:00:54 +00:00
|
|
|
list](https://github.com/PHPOffice/PhpSpreadsheet/graphs/contributors)
|
|
|
|
for up-to-date credits.
|