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 | 11 | * file have to have that font on their machine. XLSX does not embed fonts! |
|
45 | * |
||
46 | 11 | * @param string|null $fontsDirectory |
|
47 | 11 | * @param int $sheetId |
|
48 | 11 | * @throws \Exception |
|
49 | 11 | */ |
|
50 | 11 | public function __construct($fontsDirectory = null, $sheetId = 1) |
|
56 | |||
57 | /** |
||
58 | 1 | * All cells _above_ this cell (e.g. A2) will be frozen/fixed. |
|
59 | * |
||
60 | 1 | * @param string $cellId |
|
61 | 1 | */ |
|
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 | 1 | * |
|
85 | * @param array $columnWidths |
||
86 | 1 | * @throws \InvalidArgumentException |
|
87 | 1 | */ |
|
88 | public function setFixedColumnWidths(array $columnWidths) |
||
92 | |||
93 | /** |
||
94 | * Set lower and/or upper limits for column widths. |
||
95 | 1 | * |
|
96 | * @param int|float|null $minWidth |
||
97 | 1 | * @param int|float|null $maxWidth |
|
98 | 1 | */ |
|
99 | public function setColumnWidthLimits($minWidth = null, $maxWidth = null) |
||
103 | |||
104 | /** |
||
105 | 3 | * Start recording row specs for column auto-sizing. |
|
106 | * |
||
107 | 3 | * @return Writer |
|
108 | 3 | */ |
|
109 | public function enableCellAutosizing() |
||
114 | |||
115 | /** |
||
116 | 1 | * Stop recording row specs for column autosizing. |
|
117 | * |
||
118 | 1 | * @return Writer |
|
119 | 1 | */ |
|
120 | public function disableCellAutosizing() |
||
125 | |||
126 | /** |
||
127 | * Add multiple rows at once. |
||
128 | * |
||
129 | 4 | * @param array|\Traversable $rows |
|
130 | * @param Style $style |
||
131 | 4 | * @throws \InvalidArgumentException |
|
132 | 1 | */ |
|
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 | 4 | * |
|
147 | * @param array $row |
||
148 | 4 | * @param Style $style |
|
149 | 4 | */ |
|
150 | 4 | public function addRow(array $row, Style $style = null) |
|
160 | 3 | ||
161 | /** |
||
162 | 3 | * @param string|int $sheetId |
|
163 | 3 | * @param string|null $fontsDirectory |
|
164 | 3 | * @throws \Exception |
|
165 | 3 | */ |
|
166 | public function switchSheet($sheetId, $fontsDirectory = null) |
||
172 | 1 | ||
173 | /** |
||
174 | 1 | * Wrap things up and write xlsx. |
|
175 | 1 | * |
|
176 | 1 | * @param string $fileName |
|
177 | 1 | */ |
|
178 | 1 | public function writeToFile($fileName = 'report.xlsx') |
|
184 | |||
185 | 1 | /** |
|
186 | * Wrap things up and send xlsx to browser. |
||
187 | 1 | * |
|
188 | * @param string $fileName |
||
189 | */ |
||
190 | public function writeToBrowser($fileName = 'report.xlsx') |
||
197 | |||
198 | /** |
||
199 | * Send headers for browser output. |
||
200 | 1 | * |
|
201 | * @param string $fileName |
||
202 | 1 | */ |
|
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 |