| 1 |
# Architecture |
| 2 |
|
| 3 |
## Schematical |
| 4 |
|
| 5 |
 |
| 6 |
|
| 7 |
## AutoLoader |
| 8 |
|
| 9 |
PhpSpreadsheet relies on Composer autoloader. So before working with |
| 10 |
PhpSpreadsheet in standalone, be sure to run `composer install`. Or add it to a |
| 11 |
pre-existing project with `composer require phpoffice/phpspreadsheet`. |
| 12 |
|
| 13 |
## Spreadsheet in memory |
| 14 |
|
| 15 |
PhpSpreadsheet's architecture is built in a way that it can serve as an |
| 16 |
in-memory spreadsheet. This means that, if one would want to create a |
| 17 |
web based view of a spreadsheet which communicates with PhpSpreadsheet's |
| 18 |
object model, he would only have to write the front-end code. |
| 19 |
|
| 20 |
Just like desktop spreadsheet software, PhpSpreadsheet represents a |
| 21 |
spreadsheet containing one or more worksheets, which contain cells with |
| 22 |
data, formulas, images, ... |
| 23 |
|
| 24 |
## Readers and writers |
| 25 |
|
| 26 |
On its own, the `Spreadsheet` class does not provide the functionality |
| 27 |
to read from or write to a persisted spreadsheet (on disk or in a |
| 28 |
database). To provide that functionality, readers and writers can be |
| 29 |
used. |
| 30 |
|
| 31 |
By default, the PhpSpreadsheet package provides some readers and |
| 32 |
writers, including one for the Open XML spreadsheet format (a.k.a. Excel |
| 33 |
2007 file format). You are not limited to the default readers and |
| 34 |
writers, as you are free to implement the |
| 35 |
`\PhpOffice\PhpSpreadsheet\Reader\IReader` and |
| 36 |
`\PhpOffice\PhpSpreadsheet\Writer\IWriter` interface in a custom class. |
| 37 |
|
| 38 |
 |
| 39 |
|
| 40 |
## Fluent interfaces |
| 41 |
|
| 42 |
PhpSpreadsheet supports fluent interfaces in most locations. This means |
| 43 |
that you can easily "chain" calls to specific methods without requiring |
| 44 |
a new PHP statement. For example, take the following code: |
| 45 |
|
| 46 |
``` php |
| 47 |
$spreadsheet->getProperties()->setCreator("Maarten Balliauw"); |
| 48 |
$spreadsheet->getProperties()->setLastModifiedBy("Maarten Balliauw"); |
| 49 |
$spreadsheet->getProperties()->setTitle("Office 2007 XLSX Test Document"); |
| 50 |
$spreadsheet->getProperties()->setSubject("Office 2007 XLSX Test Document"); |
| 51 |
$spreadsheet->getProperties()->setDescription("Test document for Office 2007 XLSX, generated using PHP classes."); |
| 52 |
$spreadsheet->getProperties()->setKeywords("office 2007 openxml php"); |
| 53 |
$spreadsheet->getProperties()->setCategory("Test result file"); |
| 54 |
``` |
| 55 |
|
| 56 |
This can be rewritten as: |
| 57 |
|
| 58 |
``` php |
| 59 |
$spreadsheet->getProperties() |
| 60 |
->setCreator("Maarten Balliauw") |
| 61 |
->setLastModifiedBy("Maarten Balliauw") |
| 62 |
->setTitle("Office 2007 XLSX Test Document") |
| 63 |
->setSubject("Office 2007 XLSX Test Document") |
| 64 |
->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.") |
| 65 |
->setKeywords("office 2007 openxml php") |
| 66 |
->setCategory("Test result file"); |
| 67 |
``` |
| 68 |
|
| 69 |
> **Using fluent interfaces is not required** Fluent interfaces have |
| 70 |
> been implemented to provide a convenient programming API. Use of them |
| 71 |
> is not required, but can make your code easier to read and maintain. |
| 72 |
> It can also improve performance, as you are reducing the overall |
| 73 |
> number of calls to PhpSpreadsheet methods: in the above example, the |
| 74 |
> `getProperties()` method is being called only once rather than 7 times |
| 75 |
> in the non-fluent version. |
| 76 |
|