-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
116 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
/app/logs/* | ||
!app/cache/.gitkeep | ||
!app/logs/.gitkeep | ||
/examples/*.xlsx | ||
/build/ | ||
/vendor/ | ||
/bin/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# GroupedBinding | ||
|
||
To group data by a property (i.e. vertical outline) you have to define the corresponding column binding as a group-by-binding. | ||
|
||
## Code | ||
```php | ||
<?php | ||
|
||
... | ||
|
||
$zipBinding = new ColumnBinding(); | ||
$zipBinding->setLabel('Zipcode'); | ||
$zipBinding->setBinding('zipcode'); | ||
$zipBinding->setColumnWidth('auto'); | ||
$zipBinding->setOutline(1); | ||
$sheet1->addColumnBinding($zipBinding); | ||
|
||
//Group results by zip code | ||
$sheet1->setGroupByBinding($zipBinding); | ||
|
||
... | ||
|
||
``` | ||
|
||
## Result | ||
|
||
![GroupedBinding Result](images/grouped_binding.png "GroupedBinding Result") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
|
||
use StingerSoft\ExcelCreator\ConfiguredExcel; | ||
use StingerSoft\ExcelCreator\ColumnBinding; | ||
|
||
include __DIR__.'/../vendor/autoload.php'; | ||
include __DIR__.'/Person.php'; | ||
|
||
//Create excel file | ||
$excel = new ConfiguredExcel(); | ||
|
||
//and a first sheet called 'Party guests' | ||
$sheet1 = $excel->addSheet('Party guests'); | ||
|
||
//Add a column with the caption 'name' | ||
$nameBinding = new ColumnBinding(); | ||
$nameBinding->setLabel('Name'); | ||
|
||
//bind it to the property of the data to be rendered by specifying the property path (see http://symfony.com/doc/current/components/property_access.html ) | ||
$nameBinding->setBinding('name'); | ||
|
||
//Width will be calculated by excel | ||
$nameBinding->setColumnWidth('auto'); | ||
$sheet1->addColumnBinding($nameBinding); | ||
|
||
|
||
//Add a column with the caption 'E-Mail' | ||
$emailBinding = new ColumnBinding(); | ||
$emailBinding->setLabel('E-Mail'); | ||
$emailBinding->setBinding('email'); | ||
$emailBinding->setColumnWidth('auto'); | ||
$sheet1->addColumnBinding($emailBinding); | ||
|
||
//Add other information in outline 1 | ||
$streetBinding = new ColumnBinding(); | ||
$streetBinding->setLabel('Address'); | ||
$streetBinding->setBinding('address'); | ||
$streetBinding->setColumnWidth('auto'); | ||
$sheet1->addColumnBinding($streetBinding); | ||
|
||
$cityBinding = new ColumnBinding(); | ||
$cityBinding->setLabel('City'); | ||
$cityBinding->setBinding('city'); | ||
$cityBinding->setColumnWidth('auto'); | ||
$sheet1->addColumnBinding($cityBinding); | ||
|
||
$zipBinding = new ColumnBinding(); | ||
$zipBinding->setLabel('Zipcode'); | ||
$zipBinding->setBinding('zipcode'); | ||
$zipBinding->setColumnWidth('auto'); | ||
$sheet1->addColumnBinding($zipBinding); | ||
|
||
//Group results by zip code | ||
$sheet1->setGroupByBinding($zipBinding); | ||
|
||
$guests = array(); | ||
|
||
$person = new Person('Peter Mobb', 'peter@mobbtrix.de'); | ||
$person->setAddress('Musterstraße 1'); | ||
$person->setCity('Bremen'); | ||
$person->setZipCode(28357); | ||
$guests[] = $person; | ||
|
||
$person = new Person('Oliver Kotte', 'oliver.kotte@stinger-soft.net'); | ||
$person->setAddress('Musterstraße 2'); | ||
$person->setCity('Bremen'); | ||
$person->setZipCode(28357); | ||
$guests[] = $person; | ||
|
||
$person = new Person('Florian Meyer', 'florian.meyer@stinger-soft.net'); | ||
$person->setAddress('Musterstraße 3'); | ||
$person->setCity('Bremen'); | ||
$person->setZipCode(28357); | ||
$guests[] = $person; | ||
|
||
$person = new Person('Peter und Uschi', 'peter_uschi@meppen.de'); | ||
$person->setAddress('Meppstraße 1'); | ||
$person->setCity('Meppen'); | ||
$person->setZipCode(49716); | ||
$guests[] = $person; | ||
|
||
$sheet1->setData($guests); | ||
$sheet1->applyData(); | ||
|
||
\PHPExcel_IOFactory::createWriter($excel->getPhpExcel(), 'Excel2007')->save(__DIR__.'/grouped_binding.xlsx'); |