1 | <?php |
||
13 | use RuntimeException; |
||
14 | use Twig\Environment as Twig_Environment; |
||
15 | |||
16 | /** |
||
17 | * Class SheetWrapper. |
||
18 | */ |
||
19 | class SheetWrapper extends BaseWrapper |
||
20 | { |
||
21 | /** |
||
22 | * @var int |
||
23 | */ |
||
24 | const COLUMN_DEFAULT = 1; |
||
25 | /** |
||
26 | * @var int |
||
27 | */ |
||
28 | const ROW_DEFAULT = 1; |
||
29 | |||
30 | /** |
||
31 | * @var DocumentWrapper |
||
32 | */ |
||
33 | protected $documentWrapper; |
||
34 | |||
35 | /** |
||
36 | * @var Worksheet|null |
||
37 | */ |
||
38 | protected $object; |
||
39 | /** |
||
40 | * @var null|int |
||
41 | */ |
||
42 | protected $row; |
||
43 | /** |
||
44 | * @var null|int |
||
45 | */ |
||
46 | protected $column; |
||
47 | |||
48 | /** |
||
49 | * SheetWrapper constructor. |
||
50 | * |
||
51 | * @param array $context |
||
52 | * @param Twig_Environment $environment |
||
53 | * @param DocumentWrapper $documentWrapper |
||
54 | */ |
||
55 | public function __construct(array $context, Twig_Environment $environment, DocumentWrapper $documentWrapper) |
||
65 | |||
66 | /** |
||
67 | * @param int|string|null $index |
||
68 | * @param array $properties |
||
69 | * |
||
70 | * @throws Exception |
||
71 | * @throws RuntimeException |
||
72 | * @throws LogicException |
||
73 | */ |
||
74 | public function start($index, array $properties = []) |
||
99 | |||
100 | /** |
||
101 | * @throws \Exception |
||
102 | * @throws LogicException |
||
103 | */ |
||
104 | public function end() |
||
144 | |||
145 | public function increaseRow() |
||
149 | |||
150 | public function increaseColumn() |
||
154 | |||
155 | /** |
||
156 | * @return Worksheet |
||
157 | */ |
||
158 | public function getObject(): Worksheet |
||
162 | |||
163 | /** |
||
164 | * @param Worksheet $object |
||
165 | */ |
||
166 | public function setObject(Worksheet $object) |
||
170 | |||
171 | /** |
||
172 | * @return int|null |
||
173 | */ |
||
174 | public function getRow() |
||
178 | |||
179 | /** |
||
180 | * @param int|null $row |
||
181 | */ |
||
182 | public function setRow($row) |
||
186 | |||
187 | /** |
||
188 | * @return int|null |
||
189 | */ |
||
190 | public function getColumn() |
||
194 | |||
195 | /** |
||
196 | * @param int|null $column |
||
197 | */ |
||
198 | public function setColumn($column) |
||
202 | |||
203 | /** |
||
204 | * {@inheritdoc} |
||
205 | * |
||
206 | * @return array |
||
207 | */ |
||
208 | protected function configureMappings(): array |
||
209 | { |
||
210 | return [ |
||
211 | 'autoFilter' => function ($value) { $this->object->setAutoFilter($value); }, |
||
212 | 'columnDimension' => [ |
||
213 | '__multi' => function ($index = 'default'): ColumnDimension { |
||
214 | return $index === 'default' ? |
||
215 | $this->object->getDefaultColumnDimension() : |
||
216 | $this->object->getColumnDimension($index); |
||
217 | }, |
||
218 | 'autoSize' => function ($value, ColumnDimension $object) { $object->setAutoSize($value); }, |
||
219 | 'collapsed' => function ($value, ColumnDimension $object) { $object->setCollapsed($value); }, |
||
220 | 'columnIndex' => function ($value, ColumnDimension $object) { $object->setColumnIndex($value); }, |
||
221 | 'outlineLevel' => function ($value, ColumnDimension $object) { $object->setOutlineLevel($value); }, |
||
222 | 'visible' => function ($value, ColumnDimension $object) { $object->setVisible($value); }, |
||
223 | 'width' => function ($value, ColumnDimension $object) { $object->setWidth($value); }, |
||
224 | 'xfIndex' => function ($value, ColumnDimension $object) { $object->setXfIndex($value); }, |
||
225 | ], |
||
226 | 'pageMargins' => [ |
||
227 | 'top' => function ($value) { $this->object->getPageMargins()->setTop($value); }, |
||
228 | 'bottom' => function ($value) { $this->object->getPageMargins()->setBottom($value); }, |
||
229 | 'left' => function ($value) { $this->object->getPageMargins()->setLeft($value); }, |
||
230 | 'right' => function ($value) { $this->object->getPageMargins()->setRight($value); }, |
||
231 | 'header' => function ($value) { $this->object->getPageMargins()->setHeader($value); }, |
||
232 | 'footer' => function ($value) { $this->object->getPageMargins()->setFooter($value); }, |
||
233 | ], |
||
234 | 'pageSetup' => [ |
||
235 | 'fitToHeight' => function ($value) { $this->object->getPageSetup()->setFitToHeight($value); }, |
||
236 | 'fitToPage' => function ($value) { $this->object->getPageSetup()->setFitToPage($value); }, |
||
237 | 'fitToWidth' => function ($value) { $this->object->getPageSetup()->setFitToWidth($value); }, |
||
238 | 'horizontalCentered' => function ($value) { $this->object->getPageSetup()->setHorizontalCentered($value); }, |
||
239 | 'orientation' => function ($value) { $this->object->getPageSetup()->setOrientation($value); }, |
||
240 | 'paperSize' => function ($value) { $this->object->getPageSetup()->setPaperSize($value); }, |
||
241 | 'printArea' => function ($value) { $this->object->getPageSetup()->setPrintArea($value); }, |
||
242 | 'scale' => function ($value) { $this->object->getPageSetup()->setScale($value); }, |
||
243 | 'verticalCentered' => function ($value) { $this->object->getPageSetup()->setVerticalCentered($value); }, |
||
244 | ], |
||
245 | 'printGridlines' => function ($value) { $this->object->setPrintGridlines($value); }, |
||
246 | 'protection' => [ |
||
247 | 'autoFilter' => function ($value) { $this->object->getProtection()->setAutoFilter($value); }, |
||
248 | 'deleteColumns' => function ($value) { $this->object->getProtection()->setDeleteColumns($value); }, |
||
249 | 'deleteRows' => function ($value) { $this->object->getProtection()->setDeleteRows($value); }, |
||
250 | 'formatCells' => function ($value) { $this->object->getProtection()->setFormatCells($value); }, |
||
251 | 'formatColumns' => function ($value) { $this->object->getProtection()->setFormatColumns($value); }, |
||
252 | 'formatRows' => function ($value) { $this->object->getProtection()->setFormatRows($value); }, |
||
253 | 'insertColumns' => function ($value) { $this->object->getProtection()->setInsertColumns($value); }, |
||
254 | 'insertHyperlinks' => function ($value) { $this->object->getProtection()->setInsertHyperlinks($value); }, |
||
255 | 'insertRows' => function ($value) { $this->object->getProtection()->setInsertRows($value); }, |
||
256 | 'objects' => function ($value) { $this->object->getProtection()->setObjects($value); }, |
||
257 | 'password' => function ($value) { $this->object->getProtection()->setPassword($value); }, |
||
258 | 'pivotTables' => function ($value) { $this->object->getProtection()->setPivotTables($value); }, |
||
259 | 'scenarios' => function ($value) { $this->object->getProtection()->setScenarios($value); }, |
||
260 | 'selectLockedCells' => function ($value) { $this->object->getProtection()->setSelectLockedCells($value); }, |
||
261 | 'selectUnlockedCells' => function ($value) { $this->object->getProtection()->setSelectUnlockedCells($value); }, |
||
262 | 'sheet' => function ($value) { $this->object->getProtection()->setSheet($value); }, |
||
263 | 'sort' => function ($value) { $this->object->getProtection()->setSort($value); }, |
||
264 | ], |
||
265 | 'rightToLeft' => function ($value) { $this->object->setRightToLeft($value); }, |
||
266 | 'rowDimension' => [ |
||
267 | '__multi' => function ($index = 'default'): RowDimension { |
||
268 | return $index === 'default' ? |
||
269 | $this->object->getDefaultRowDimension() : |
||
270 | $this->object->getRowDimension($index); |
||
271 | }, |
||
272 | 'collapsed' => function ($value, RowDimension $object) { $object->setCollapsed($value); }, |
||
273 | 'outlineLevel' => function ($value, RowDimension $object) { $object->setOutlineLevel($value); }, |
||
274 | 'rowHeight' => function ($value, RowDimension $object) { $object->setRowHeight($value); }, |
||
275 | 'rowIndex' => function ($value, RowDimension $object) { $object->setRowIndex($value); }, |
||
276 | 'visible' => function ($value, RowDimension $object) { $object->setVisible($value); }, |
||
277 | 'xfIndex' => function ($value, RowDimension $object) { $object->setXfIndex($value); }, |
||
278 | 'zeroHeight' => function ($value, RowDimension $object) { $object->setZeroHeight($value); }, |
||
279 | ], |
||
280 | 'sheetState' => function ($value) { $this->object->setSheetState($value); }, |
||
281 | 'showGridlines' => function ($value) { $this->object->setShowGridlines($value); }, |
||
287 |