Completed
Push — master ( 5dab40...ca534d )
by Maxime
120:18 queued 114:35
created

ExcelExporter::export()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 38
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 38
ccs 0
cts 28
cp 0
rs 8.8571
cc 2
eloc 17
nc 2
nop 2
crap 6
1
<?php
2
/**
3
     * Created by PhpStorm.
4
     * User: mfrancois
5
     * Date: 6/02/2015
6
     * Time: 4:37 PM
7
     */
8
9
namespace Distilleries\Expendable\Exporter;
10
11
use Distilleries\Expendable\Contracts\ExcelExporterContract;
12
13
class ExcelExporter implements ExcelExporterContract {
14
15
16
    public function export($data, $filename = '')
17
    {
18
19
20
        $excel = \Excel::create($filename, function($excel) use ($data)
21
        {
22
23
            $excel->sheet('export', function($sheet) use ($data)
24
            {
25
26
                $sheet->fromArray($data);
27
                $sheet->freezeFirstRow();
28
                $sheet->setAutoFilter();
29
                $sheet->row(1, function($row)
30
                {
31
                    $row->setValignment('middle');
32
                    $row->setAlignment('center');
33
                    $row->setFontColor('#ffffff');
34
                    $row->setFont(array(
35
                        'size' => '12',
36
                        'bold' => true
37
                    ));
38
                    $row->setBackground('#000000');
39
40
                });
41
42
            });
43
44
45
        });
46
47
        if (app()->environment('testing'))
48
        {
49
            $excel->store('xls');
50
        }
51
52
        $excel->export('xls')->download('xls');
53
    }
54
}