PhpSpreadsheet/docs/Overview/03-Creating-a-Spreadsheet.md

35 lines
1.4 KiB
Markdown
Raw Normal View History

2016-11-27 15:51:44 +00:00
# PhpSpreadsheet Developer Documentation
2013-05-16 20:59:54 +00:00
2013-05-19 21:14:52 +00:00
2013-05-16 20:59:54 +00:00
## Creating a spreadsheet
2016-11-27 15:51:44 +00:00
### The `Spreadsheet` class
2013-05-16 20:59:54 +00:00
2016-11-27 15:51:44 +00:00
The `Spreadsheet` class is the core of PhpSpreadsheet. It contains references to the contained worksheets, document security settings and document meta data.
2013-05-16 20:59:54 +00:00
2016-11-27 15:51:44 +00:00
To simplify the PhpSpreadsheet concept: the `Spreadsheet` class represents your workbook.
2013-05-16 20:59:54 +00:00
Typically, you will create a workbook in one of two ways, either by loading it from a spreadsheet file, or creating it manually. A third option, though less commonly used, is cloning an existing workbook that has been created using one of the previous two methods.
#### Loading a Workbook from a file
2016-11-27 15:51:44 +00:00
Details of the different spreadsheet formats supported, and the options available to read them into a Spreadsheet object are described fully in the PhpSpreadsheet User Documentation - Reading Spreadsheet Files document.
2013-05-16 20:59:54 +00:00
```php
$inputFileName = './sampleData/example1.xls';
2016-11-27 15:51:44 +00:00
/** Load $inputFileName to a Spreadsheet object **/
$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($inputFileName);
2013-05-16 20:59:54 +00:00
```
#### Creating a new workbook
2016-11-27 15:51:44 +00:00
If you want to create a new workbook, rather than load one from file, then you simply need to instantiate it as a new Spreadsheet object.
2013-05-16 20:59:54 +00:00
```php
2016-11-27 15:51:44 +00:00
/** Create a new Spreadsheet Object **/
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
2013-05-16 20:59:54 +00:00
```
A new workbook will always be created with a single worksheet.