Skip to content

Commit 7ccf9ff

Browse files
committed
Update README
1 parent 016e259 commit 7ccf9ff

File tree

2 files changed

+67
-2
lines changed

2 files changed

+67
-2
lines changed

README.md

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Install the package with [composer](http://getcomposer.org):
4242

4343
## Examples
4444

45-
For now we only provide some usage examples instead of a full documentation.
45+
Instead of a full documentation we better show you some examples. You should be able to take it from there.
4646

4747
### ActiveQuery results
4848

@@ -155,3 +155,66 @@ $file = \Yii::createObject([
155155
]);
156156
$file->send('demo.xlsx');
157157
```
158+
159+
### Styling
160+
161+
As you have access to the `PHPExcel` object you can modify the excel file as you like:
162+
163+
```php
164+
<?php
165+
$file = \Yii::createObject([
166+
'class' => 'codemix\excelexport\ExcelFile',
167+
'sheets' => [
168+
'Users' => [
169+
'class' => 'codemix\excelexport\ActiveExcelSheet',
170+
'query' => User::find(),
171+
]
172+
]
173+
]);
174+
$phpExcel = $file->getWorkbook();
175+
$phpExcel->getSheet(1)->getStyle('B1')
176+
->getFont()->getColor()->setARGB(\PHPExcel_Style_Color::COLOR_RED);
177+
```
178+
179+
Alternatively you can use the callback feature from our `ExcelSheet`:
180+
181+
```php
182+
<?php
183+
$file = \Yii::createObject([
184+
'class' => 'codemix\excelexport\ExcelFile',
185+
'sheets' => [
186+
'Users' => [
187+
'class' => 'codemix\excelexport\ActiveExcelSheet',
188+
'query' => User::find(),
189+
'callbacks' => [
190+
// $cell is a PHPExcel_Cell object
191+
'A' => function ($cell, $row, $column) {
192+
$cell->getStyle()->applyFromArray([
193+
'font' => [
194+
'bold' => true,
195+
],
196+
'alignment' => [
197+
'horizontal' => \PHPExcel_Style_Alignment::HORIZONTAL_RIGHT,
198+
],
199+
'borders' => [
200+
'top' => [
201+
'style' => \PHPExcel_Style_Border::BORDER_THIN,
202+
],
203+
],
204+
'fill' => [
205+
'type' => \PHPExcel_Style_Fill::FILL_GRADIENT_LINEAR,
206+
'rotation' => 90,
207+
'startcolor' => [
208+
'argb' => 'FFA0A0A0',
209+
],
210+
'endcolor' => [
211+
'argb' => 'FFFFFFFF',
212+
],
213+
],
214+
]);
215+
},
216+
],
217+
],
218+
],
219+
]);
220+

src/ExcelFile.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ public function getSheets()
5151
}
5252

5353
/**
54-
* @param array $value the sheet configuration
54+
* @param array $value the sheet configuration. This must be an array where keys
55+
* are sheet names and values are arrays with the configuration options for an
56+
* instance if `ExcelSheet`.
5557
*/
5658
public function setSheets($value)
5759
{

0 commit comments

Comments
 (0)