Download the PHP package dfware/spreadsheet without Composer
On this page you can find all versions of the php package dfware/spreadsheet. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download dfware/spreadsheet
More information about dfware/spreadsheet
Files in dfware/spreadsheet
Package spreadsheet
Short Description Yii2 extension for export to a spreadsheet, e.g. Excel, LibreOffice etc.
License BSD-3-Clause
Informations about the package spreadsheet
Installation
The preferred way to install this extension is through composer.
Either run
or add
to the require section of your composer.json.
Usage
This extension provides ability to export data to a spreadsheet, e.g. Excel, LibreOffice etc.
It is powered by phpoffice/phpspreadsheet library.
Export is performed via \yii2tech\spreadsheet\Spreadsheet
instance, which provides interface similar to \yii\grid\GridView
widget.
Example:
Please, refer to \yii2tech\spreadsheet\Column
class for the information about column properties and configuration specifications.
While running web application you can use \yii2tech\spreadsheet\Spreadsheet::send()
method to send a result file to
the browser through download dialog:
Multiple sheet files
You can create an output file with multiple worksheets (tabs). For example: you may want to export data about
equipment used in the office, keeping monitors, mouses, keyboards and so on in separated listings but in the same file.
To do so you will need to manually call \yii2tech\spreadsheet\Spreadsheet::render()
method with different configuration
before creating final file. For example:
As the result you will get a single *.xls file with 3 worksheets (tabs): 'Monitors', 'Mouses' and 'Keyboards'.
Using \yii2tech\spreadsheet\Spreadsheet::configure()
you can reset any spreadsheet parameter, including columns
.
Thus you are able to combine several entirely different sheets into a single file.
Large data processing
\yii2tech\spreadsheet\Spreadsheet
allows exporting of the \yii\data\DataProviderInterface
and \yii\db\QueryInterface
instances.
Export is performed via batches, which allows processing of the large data without memory overflow.
In case of \yii\data\DataProviderInterface
usage, data will be split to batches using pagination mechanism.
Thus you should setup pagination with page size in order to control batch size:
Note: if you disable pagination in your data provider - no batch processing will be performed.
In case of \yii\db\QueryInterface
usage, Spreadsheet
will attempt to use batch()
method, if it is present in the query
class (for example in case \yii\db\Query
or \yii\db\ActiveQuery
usage). If batch()
method is not available -
yii\data\ActiveDataProvider
instance will be automatically created around given query.
You can control batch size via \yii2tech\spreadsheet\Spreadsheet::$batchSize
:
Note: despite batch data processing reduces amount of resources needed for spreadsheet file generation, your program may still easily end up with PHP memory limit error on large data. This happens because of large complexity of the created document, which is stored in the memory during the entire process. In case you need to export really large data set, consider doing so via simple CSV data format using yii2tech/csv-grid extension.
Complex headers
You may union some columns in the sheet header into a groups. For example: you may have 2 different data columns:
'Planned Revenue' and 'Actual Revenue'. In this case you may want to display them as a single column 'Revenue', split
into 2 sub columns: 'Planned' and 'Actual'.
This can be achieved using \yii2tech\spreadsheet\Spreadsheet::$headerColumnUnions
. Its each entry
should specify 'offset', which determines the amount of columns to be skipped, and 'length', which determines
the amount of columns to be united. Other options of the union are the same as for regular column.
For example:
Note: only single level of header column unions is supported. You will need to deal with more complex cases on your own.
Custom cell rendering
Before save()
or send()
method is invoked, you are able to edit generated spreadsheet, making some
final adjustments to it. Several methods exist to facilitate this process:
\yii2tech\spreadsheet\Spreadsheet::renderCell()
- renders specified cell with given content and style.\yii2tech\spreadsheet\Spreadsheet::applyCellStyle()
- applies specified style to the cell.\yii2tech\spreadsheet\Spreadsheet::mergeCells()
- merges sell range into single one.
You may use these methods, after document has been composed via \yii2tech\spreadsheet\Spreadsheet::render()
,
to override or add some content. For example:
Tip: you can use
\yii2tech\spreadsheet\Spreadsheet::$rowIndex
to get number of the row, which is next to the last rendered one.