1 | <?php |
||
9 | class Writer |
||
10 | { |
||
11 | /** |
||
12 | * @var SheetFile[] |
||
13 | */ |
||
14 | private $sheetFiles; |
||
15 | |||
16 | /** |
||
17 | * @var Styler |
||
18 | */ |
||
19 | private $styler; |
||
20 | |||
21 | /** |
||
22 | * @var Sheet[] |
||
23 | */ |
||
24 | private $sheets; |
||
25 | |||
26 | /** |
||
27 | * @var Workbook |
||
28 | */ |
||
29 | private $workbook; |
||
30 | |||
31 | /** |
||
32 | * @var resource |
||
33 | */ |
||
34 | private $output; |
||
35 | |||
36 | /** |
||
37 | * @var string |
||
38 | */ |
||
39 | private $currentSheet; |
||
40 | |||
41 | /** |
||
42 | * If a $fontsDirectory is supplied it will be scanned for usable ttf/otf fonts |
||
43 | * to be used for cell auto-sizing. Keep in mind though - viewers of an excel |
||
44 | * file have to have that font on their machine. XLSX does not embed fonts! |
||
45 | * |
||
46 | * @param string|null $fontsDirectory |
||
47 | * @param string|int $sheetName |
||
48 | * @throws \Exception |
||
49 | */ |
||
50 | 14 | public function __construct($fontsDirectory = null, $sheetName = 'sheet1') |
|
56 | |||
57 | /** |
||
58 | * All cells _above_ this cell (e.g. A2) will be frozen/fixed. |
||
59 | * |
||
60 | * @param string $cellId |
||
61 | */ |
||
62 | 1 | public function setFreezePaneCellId($cellId) |
|
66 | |||
67 | /** |
||
68 | * Set the range of rows to repeat at the top of each page when printing the |
||
69 | * excel file. $startRow=1 and $endRow=1 will repeat the first row only. |
||
70 | * |
||
71 | * @param int $startRow |
||
72 | * @param int $endRow |
||
73 | */ |
||
74 | 1 | public function setPrintTitleRange($startRow, $endRow) |
|
75 | { |
||
76 | 1 | $this->workbook->setPrintTitleRange($startRow, $endRow, $this->currentSheet); |
|
77 | 1 | } |
|
78 | |||
79 | /** |
||
80 | * Set fixed column widths per cell (no ranges) and array index |
||
81 | * 0 being the first column. |
||
82 | * If used alongside cell autosizing, these should be set |
||
83 | * after the last row has been added. |
||
84 | * |
||
85 | * @param array $columnWidths |
||
86 | * @throws \InvalidArgumentException |
||
87 | */ |
||
88 | 1 | public function setFixedColumnWidths(array $columnWidths) |
|
92 | |||
93 | /** |
||
94 | * Set lower and/or upper limits for column widths. |
||
95 | * |
||
96 | * @param int|float|null $minWidth |
||
97 | * @param int|float|null $maxWidth |
||
98 | */ |
||
99 | 1 | public function setColumnWidthLimits($minWidth = null, $maxWidth = null) |
|
103 | |||
104 | /** |
||
105 | * Start recording row specs for column auto-sizing. |
||
106 | * |
||
107 | * @return Writer |
||
108 | */ |
||
109 | 3 | public function enableCellAutosizing() |
|
114 | |||
115 | /** |
||
116 | * Stop recording row specs for column auto-sizing. |
||
117 | * |
||
118 | * @return Writer |
||
119 | */ |
||
120 | 1 | public function disableCellAutosizing() |
|
125 | |||
126 | /** |
||
127 | * Add multiple rows at once. |
||
128 | * |
||
129 | * @param array|\Traversable $rows |
||
130 | * @param Style $style |
||
131 | * @throws \InvalidArgumentException |
||
132 | */ |
||
133 | 4 | public function addRows($rows, Style $style = null) |
|
143 | |||
144 | /** |
||
145 | * Add a single new row to the sheet and supply an optional style. |
||
146 | * |
||
147 | * @param array $row |
||
148 | * @param Style $style |
||
149 | */ |
||
150 | 4 | public function addRow(array $row, Style $style = null) |
|
160 | |||
161 | /** |
||
162 | * @param string|int $sheetName |
||
163 | * @param string|null $fontsDirectory |
||
164 | * @throws \Exception |
||
165 | */ |
||
166 | 14 | public function switchSheet($sheetName, $fontsDirectory = null) |
|
172 | |||
173 | /** |
||
174 | * Wrap things up and write xlsx. |
||
175 | * |
||
176 | * @param string $fileName |
||
177 | */ |
||
178 | 3 | public function writeToFile($fileName = 'report.xlsx') |
|
184 | |||
185 | /** |
||
186 | * Wrap things up and send xlsx to browser. |
||
187 | * |
||
188 | * @param string $fileName |
||
189 | */ |
||
190 | 1 | public function writeToBrowser($fileName = 'report.xlsx') |
|
197 | |||
198 | /** |
||
199 | * Send headers for browser output. |
||
200 | * |
||
201 | * @param string $fileName |
||
202 | */ |
||
203 | 1 | private function sendHeaders($fileName) |
|
212 | |||
213 | /** |
||
214 | * @param string $fontsDirectory |
||
215 | * @param string $sheetName |
||
216 | * @throws \Exception|\InvalidArgumentException |
||
217 | */ |
||
218 | 14 | private function createNewSheet($fontsDirectory, $sheetName) |
|
230 | |||
231 | /** |
||
232 | * Return array of available fonts & paths as key value pairs. |
||
233 | * |
||
234 | * @return array |
||
235 | */ |
||
236 | 1 | public function getFonts() |
|
240 | } |
||
241 |