1 | <?php |
||
14 | class Finalizer |
||
15 | { |
||
16 | /** |
||
17 | * @var Sheet |
||
18 | */ |
||
19 | private $sheet; |
||
20 | |||
21 | /** |
||
22 | * @var SheetFile |
||
23 | */ |
||
24 | private $sheetFile; |
||
25 | |||
26 | /** |
||
27 | * @var \ZipArchive |
||
28 | */ |
||
29 | private $zip; |
||
30 | |||
31 | /** |
||
32 | * @var Styler |
||
33 | */ |
||
34 | private $styler; |
||
35 | |||
36 | /** |
||
37 | * Finalizer constructor. |
||
38 | * |
||
39 | * @param Sheet $sheet |
||
40 | * @param Styler $styler |
||
41 | * @param SheetFile $sheetFile |
||
42 | */ |
||
43 | 2 | public function __construct(Sheet $sheet, Styler $styler, SheetFile $sheetFile) |
|
50 | |||
51 | /** |
||
52 | * Finalize the xlsx file. |
||
53 | * |
||
54 | * @param string $fileName |
||
55 | * @throws \RuntimeException |
||
56 | */ |
||
57 | 2 | public function finalize($fileName) |
|
69 | |||
70 | /** |
||
71 | * Wrap up the sheet (write header, column xmls). |
||
72 | */ |
||
73 | 2 | private function finalizeSheet() |
|
74 | { |
||
75 | 2 | $this->sheetFile->fwrite('</sheetData></worksheet>'); |
|
76 | 2 | $this->sheetFile->rewind(); |
|
77 | 2 | $this->sheetFile->fwrite(SheetXml::HEADER_XML); |
|
78 | 2 | $this->sheetFile->fwrite($this->sheet->getDimensionXml()); |
|
79 | 2 | $this->sheetFile->fwrite($this->sheet->getSheetViewsXml()); |
|
80 | 2 | $this->writeColumnWidths(); |
|
81 | 2 | $this->zip->addFile($this->sheetFile->getFilePath(), 'xl/worksheets/sheet1.xml'); |
|
82 | 2 | } |
|
83 | |||
84 | /** |
||
85 | * Write column widths xml string. |
||
86 | */ |
||
87 | 2 | private function writeColumnWidths() |
|
100 | |||
101 | /** |
||
102 | * Write style xml file. |
||
103 | */ |
||
104 | 2 | private function finalizeStyles() |
|
108 | |||
109 | /** |
||
110 | * Add default xmls to zip archive. |
||
111 | */ |
||
112 | 2 | private function finalizeDefaultXmls() |
|
122 | } |
||
123 |