|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace MewesK\TwigExcelBundle\Wrapper; |
|
4
|
|
|
use Twig_Environment; |
|
5
|
|
|
|
|
6
|
|
|
/** |
|
7
|
|
|
* Class PhpExcelWrapper |
|
8
|
|
|
* |
|
9
|
|
|
* @package MewesK\TwigExcelBundle\Wrapper |
|
10
|
|
|
*/ |
|
11
|
|
|
class PhpExcelWrapper |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* @var XlsDocumentWrapper |
|
15
|
|
|
*/ |
|
16
|
|
|
private $documentWrapper; |
|
17
|
|
|
/** |
|
18
|
|
|
* @var XlsSheetWrapper |
|
19
|
|
|
*/ |
|
20
|
|
|
private $sheetWrapper; |
|
21
|
|
|
/** |
|
22
|
|
|
* @var XlsRowWrapper |
|
23
|
|
|
*/ |
|
24
|
|
|
private $rowWrapper; |
|
25
|
|
|
/** |
|
26
|
|
|
* @var XlsCellWrapper |
|
27
|
|
|
*/ |
|
28
|
|
|
private $cellWrapper; |
|
29
|
|
|
/** |
|
30
|
|
|
* @var XlsHeaderFooterWrapper |
|
31
|
|
|
*/ |
|
32
|
|
|
private $headerFooterWrapper; |
|
33
|
|
|
/** |
|
34
|
|
|
* @var XlsDrawingWrapper |
|
35
|
|
|
*/ |
|
36
|
|
|
private $drawingWrapper; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @var int |
|
40
|
|
|
*/ |
|
41
|
|
|
private $cellIndex; |
|
42
|
|
|
/** |
|
43
|
|
|
* @var int |
|
44
|
|
|
*/ |
|
45
|
|
|
private $rowIndex; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* PhpExcelWrapper constructor. |
|
49
|
|
|
* @param array $context |
|
50
|
|
|
* @param Twig_Environment $environment |
|
51
|
|
|
*/ |
|
52
|
|
|
public function __construct(array $context = [], Twig_Environment $environment) |
|
53
|
|
|
{ |
|
54
|
|
|
$this->documentWrapper = new XlsDocumentWrapper($context, $environment); |
|
55
|
|
|
$this->sheetWrapper = new XlsSheetWrapper($context, $environment, $this->documentWrapper); |
|
56
|
|
|
$this->rowWrapper = new XlsRowWrapper($context, $environment, $this->sheetWrapper); |
|
57
|
|
|
$this->cellWrapper = new XlsCellWrapper($context, $environment, $this->sheetWrapper); |
|
58
|
|
|
$this->headerFooterWrapper = new XlsHeaderFooterWrapper($context, $environment, $this->sheetWrapper); |
|
59
|
|
|
$this->drawingWrapper = new XlsDrawingWrapper($context, $environment, $this->sheetWrapper, $this->headerFooterWrapper); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
// |
|
63
|
|
|
// Tags |
|
64
|
|
|
// |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @param null|array $properties |
|
68
|
|
|
* |
|
69
|
|
|
* @throws \PHPExcel_Exception |
|
70
|
|
|
*/ |
|
71
|
|
|
public function startDocument(array $properties = null) |
|
72
|
|
|
{ |
|
73
|
|
|
$this->documentWrapper->start($properties); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @throws \PHPExcel_Reader_Exception |
|
78
|
|
|
* @throws \PHPExcel_Exception |
|
79
|
|
|
* @throws \InvalidArgumentException |
|
80
|
|
|
* @throws \PHPExcel_Writer_Exception |
|
81
|
|
|
*/ |
|
82
|
|
|
public function endDocument() |
|
83
|
|
|
{ |
|
84
|
|
|
$this->documentWrapper->end(); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* @param string $index |
|
89
|
|
|
* @param null|array $properties |
|
90
|
|
|
* @throws \PHPExcel_Exception |
|
91
|
|
|
*/ |
|
92
|
|
|
public function startSheet($index, array $properties = null) |
|
93
|
|
|
{ |
|
94
|
|
|
$this->sheetWrapper->start($index, $properties); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
public function endSheet() |
|
98
|
|
|
{ |
|
99
|
|
|
$this->sheetWrapper->end(); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
public function startRow() |
|
103
|
|
|
{ |
|
104
|
|
|
$this->rowWrapper->start($this->rowIndex); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
public function endRow() |
|
108
|
|
|
{ |
|
109
|
|
|
$this->rowWrapper->end(); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* @param null|mixed $value |
|
114
|
|
|
* @param null|array $properties |
|
115
|
|
|
* @throws \PHPExcel_Exception |
|
116
|
|
|
* @throws \InvalidArgumentException |
|
117
|
|
|
* @throws \LogicException |
|
118
|
|
|
*/ |
|
119
|
|
|
public function startCell($value = null, array $properties = null) |
|
120
|
|
|
{ |
|
121
|
|
|
$this->cellWrapper->start($this->cellIndex, $value, $properties); |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
public function endCell() |
|
125
|
|
|
{ |
|
126
|
|
|
$this->cellWrapper->end(); |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
/** |
|
130
|
|
|
* @param string $type |
|
131
|
|
|
* @param null|array $properties |
|
132
|
|
|
* @throws \LogicException |
|
133
|
|
|
*/ |
|
134
|
|
|
public function startHeaderFooter($type, array $properties = null) |
|
135
|
|
|
{ |
|
136
|
|
|
$this->headerFooterWrapper->start($type, $properties); |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
public function endHeaderFooter() |
|
140
|
|
|
{ |
|
141
|
|
|
$this->headerFooterWrapper->end(); |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
/** |
|
145
|
|
|
* @param null|string $type |
|
146
|
|
|
* @param null|array $properties |
|
147
|
|
|
* @throws \InvalidArgumentException |
|
148
|
|
|
*/ |
|
149
|
|
|
public function startAlignment($type = null, array $properties = null) |
|
150
|
|
|
{ |
|
151
|
|
|
$this->headerFooterWrapper->startAlignment($type, $properties); |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
/** |
|
155
|
|
|
* @param null|string $value |
|
156
|
|
|
* @throws \InvalidArgumentException |
|
157
|
|
|
*/ |
|
158
|
|
|
public function endAlignment($value = null) |
|
159
|
|
|
{ |
|
160
|
|
|
$this->headerFooterWrapper->endAlignment($value); |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
/** |
|
164
|
|
|
* @param string $path |
|
165
|
|
|
* @param array $properties |
|
166
|
|
|
* @throws \PHPExcel_Exception |
|
167
|
|
|
* @throws \InvalidArgumentException |
|
168
|
|
|
* @throws \LogicException |
|
169
|
|
|
* @throws \RuntimeException |
|
170
|
|
|
*/ |
|
171
|
|
|
public function startDrawing($path, array $properties = null) |
|
172
|
|
|
{ |
|
173
|
|
|
$this->drawingWrapper->start($path, $properties); |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
public function endDrawing() |
|
177
|
|
|
{ |
|
178
|
|
|
$this->drawingWrapper->end(); |
|
179
|
|
|
} |
|
180
|
|
|
|
|
181
|
|
|
// Getter / Setter |
|
182
|
|
|
|
|
183
|
|
|
/** |
|
184
|
|
|
* @return int |
|
185
|
|
|
*/ |
|
186
|
|
|
public function getCellIndex() |
|
187
|
|
|
{ |
|
188
|
|
|
return $this->cellIndex; |
|
189
|
|
|
} |
|
190
|
|
|
|
|
191
|
|
|
/** |
|
192
|
|
|
* @param int $cellIndex |
|
193
|
|
|
*/ |
|
194
|
|
|
public function setCellIndex($cellIndex) |
|
195
|
|
|
{ |
|
196
|
|
|
$this->cellIndex = $cellIndex; |
|
197
|
|
|
} |
|
198
|
|
|
|
|
199
|
|
|
/** |
|
200
|
|
|
* @return int |
|
201
|
|
|
*/ |
|
202
|
|
|
public function getRowIndex() |
|
203
|
|
|
{ |
|
204
|
|
|
return $this->rowIndex; |
|
205
|
|
|
} |
|
206
|
|
|
|
|
207
|
|
|
/** |
|
208
|
|
|
* @param int $rowIndex |
|
209
|
|
|
*/ |
|
210
|
|
|
public function setRowIndex($rowIndex) |
|
211
|
|
|
{ |
|
212
|
|
|
$this->rowIndex = $rowIndex; |
|
213
|
|
|
} |
|
214
|
|
|
} |
|
215
|
|
|
|