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|int |
||
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 int $sheetId |
||
48 | * @throws \Exception |
||
49 | */ |
||
50 | public function __construct($fontsDirectory = null, $sheetId = 1) |
||
56 | |||
57 | /** |
||
58 | * All cells _above_ this cell (e.g. A2) will be frozen/fixed. |
||
59 | * |
||
60 | * @param string $cellId |
||
61 | */ |
||
62 | 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 | public function setPrintTitleRange($startRow, $endRow) |
||
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 | 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 | public function setColumnWidthLimits($minWidth = null, $maxWidth = null) |
||
103 | |||
104 | /** |
||
105 | * Start recording row specs for column auto-sizing. |
||
106 | * |
||
107 | * @return Writer |
||
108 | */ |
||
109 | public function enableCellAutosizing() |
||
114 | |||
115 | /** |
||
116 | * Stop recording row specs for column autosizing. |
||
117 | * |
||
118 | * @return Writer |
||
119 | */ |
||
120 | 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 | 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 | public function addRow(array $row, Style $style = null) |
||
160 | |||
161 | /** |
||
162 | * @param string|int $sheetId |
||
163 | * @param string|null $fontsDirectory |
||
164 | * @throws \Exception |
||
165 | */ |
||
166 | public function switchSheet($sheetId, $fontsDirectory = null) |
||
172 | |||
173 | /** |
||
174 | * Wrap things up and write xlsx. |
||
175 | * |
||
176 | * @param string $fileName |
||
177 | */ |
||
178 | public function writeToFile($fileName = 'report.xlsx') |
||
184 | |||
185 | /** |
||
186 | * Wrap things up and send xlsx to browser. |
||
187 | * |
||
188 | * @param string $fileName |
||
189 | */ |
||
190 | public function writeToBrowser($fileName = 'report.xlsx') |
||
197 | |||
198 | /** |
||
199 | * Send headers for browser output. |
||
200 | * |
||
201 | * @param string $fileName |
||
202 | */ |
||
203 | private function sendHeaders($fileName) |
||
212 | |||
213 | /** |
||
214 | * Return array of available fonts & paths as key value pairs. |
||
215 | * |
||
216 | * @return array |
||
217 | */ |
||
218 | public function getFonts() |
||
222 | |||
223 | /** |
||
224 | * @param string $fontsDirectory |
||
225 | * @param int $sheetId |
||
226 | * @throws \Exception |
||
227 | */ |
||
228 | private function createNewSheet($fontsDirectory, $sheetId) |
||
234 | } |
||
235 |