1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Onurb\Bundle\ExcelBundle\Factory; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\HttpFoundation\StreamedResponse; |
6
|
|
|
use PhpOffice\PhpSpreadsheet\Helper\Html; |
7
|
|
|
use PhpOffice\PhpSpreadsheet\Reader\IReader; |
8
|
|
|
use PhpOffice\PhpSpreadsheet\Spreadsheet; |
9
|
|
|
use PhpOffice\PhpSpreadsheet\Worksheet\Drawing; |
10
|
|
|
use PhpOffice\PhpSpreadsheet\Writer\IWriter; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Factory for Spreadsheet objects |
14
|
|
|
* |
15
|
|
|
* Factory inspired by the liuggio\ExcelBundle\Factory, migrated for phpoffice/phpSpreadSheet Usage |
16
|
|
|
* (PhpExcel used by liuggio is abandoned) |
17
|
|
|
* |
18
|
|
|
* @package Onurb\Bundle\ExcelBundle |
19
|
|
|
*/ |
20
|
|
|
class CompatibilityFactory |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @var ExcelFactory |
24
|
|
|
*/ |
25
|
|
|
private $factory; |
26
|
|
|
|
27
|
11 |
|
public function __construct(ExcelFactory $factory = null) |
28
|
|
|
{ |
29
|
11 |
|
$this->factory = $factory ? $factory : new ExcelFactory(); |
30
|
11 |
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Creates an empty Spreadsheet Object if the filename is empty, otherwise loads the file into the object. |
34
|
|
|
* |
35
|
|
|
* @param string $filename |
36
|
|
|
* |
37
|
|
|
* @return Spreadsheet |
38
|
|
|
*/ |
39
|
6 |
|
public function createPHPExcelObject($filename = null) |
40
|
|
|
{ |
41
|
6 |
|
return $this->factory->createSpreadsheet($filename); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @return Drawing |
46
|
|
|
*/ |
47
|
2 |
|
public function createPHPExcelWorksheetDrawing() |
48
|
|
|
{ |
49
|
2 |
|
return $this->factory->createSpreadsheetWorksheetDrawing(); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Create a reader |
54
|
|
|
* |
55
|
|
|
* @param string $type |
56
|
|
|
* |
57
|
|
|
* @return IReader |
58
|
|
|
*/ |
59
|
2 |
|
public function createReader($type = 'Xlsx') |
60
|
|
|
{ |
61
|
2 |
|
return $this->factory->createReader($type); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Create a writer given the PHPExcelObject and the type, |
66
|
|
|
* |
67
|
|
|
* @param Spreadsheet $phpExcelObject |
68
|
|
|
* @param string $type |
69
|
|
|
* @return IWriter |
70
|
|
|
*/ |
71
|
5 |
|
public function createWriter(Spreadsheet $phpExcelObject, $type = 'Xlsx') |
72
|
|
|
{ |
73
|
5 |
|
return $this->factory->createWriter($phpExcelObject, $type); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Stream the file as Response. |
78
|
|
|
* |
79
|
|
|
* @param IWriter $writer |
80
|
|
|
* @param int $status |
81
|
|
|
* @param array $headers |
82
|
|
|
* |
83
|
|
|
* @return StreamedResponse |
84
|
|
|
*/ |
85
|
2 |
|
public function createStreamedResponse(IWriter $writer, $status = 200, $headers = array()) |
86
|
|
|
{ |
87
|
2 |
|
return $this->factory->createStreamedResponse($writer, $status, $headers); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Create a PHPExcel Helper HTML Object |
92
|
|
|
* |
93
|
|
|
* @return Html |
94
|
|
|
*/ |
95
|
5 |
|
public function createHelperHTML() |
96
|
|
|
{ |
97
|
5 |
|
return $this->factory->createHelperHTML(); |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|