1 | <?php |
||
9 | class Writer |
||
10 | { |
||
11 | /** |
||
12 | * @var SheetFile |
||
13 | */ |
||
14 | private $sheetFile; |
||
15 | |||
16 | /** |
||
17 | * @var Styler |
||
18 | */ |
||
19 | private $styler; |
||
20 | |||
21 | /** |
||
22 | * @var Sheet |
||
23 | */ |
||
24 | private $sheet; |
||
25 | |||
26 | /** |
||
27 | * @var Workbook |
||
28 | */ |
||
29 | private $workbook; |
||
30 | |||
31 | /** |
||
32 | * @var resource |
||
33 | */ |
||
34 | private $output; |
||
35 | |||
36 | /** |
||
37 | * If a $fontsDirectory is supplied it will be scanned for usable ttf/otf fonts |
||
38 | * to be used for cell auto-sizing. Keep in mind though - viewers of an excel |
||
39 | * file have to have that font on their machine. XLSX does not embed fonts! |
||
40 | * |
||
41 | * @param string|null $fontsDirectory |
||
42 | * @throws \Exception |
||
43 | */ |
||
44 | public function __construct($fontsDirectory = null) |
||
52 | |||
53 | /** |
||
54 | * All cells _above_ this cell (e.g. A2) will be frozen/fixed. |
||
55 | * |
||
56 | * @param string $cellId |
||
57 | */ |
||
58 | public function setFreezePaneCellId($cellId) |
||
62 | |||
63 | /** |
||
64 | * Set the range of rows to repeat at the top of each page when printing the |
||
65 | * excel file. $startRow=1 and $endRow=1 will repeat the first row only. |
||
66 | * |
||
67 | * @param int $startRow |
||
68 | * @param int $endRow |
||
69 | */ |
||
70 | public function setPrintTitleRange($startRow, $endRow) |
||
74 | |||
75 | /** |
||
76 | * Set fixed column widths per cell (no ranges) and array index |
||
77 | * 0 being the first column. |
||
78 | * If used alongside cell autosizing, these should be set |
||
79 | * after the last row has been added. |
||
80 | * |
||
81 | * @param array $columnWidths |
||
82 | * @throws \InvalidArgumentException |
||
83 | */ |
||
84 | public function setFixedColumnWidths(array $columnWidths) |
||
88 | |||
89 | /** |
||
90 | * Set lower and/or upper limits for column widths. |
||
91 | * |
||
92 | * @param float|null $minWidth |
||
93 | * @param float|null $maxWidth |
||
94 | */ |
||
95 | public function setColumnWidthLimits($minWidth = null, $maxWidth = null) |
||
99 | |||
100 | /** |
||
101 | * Start recording row specs for column auto-sizing. |
||
102 | * |
||
103 | * @return Writer |
||
104 | */ |
||
105 | public function enableCellAutosizing() |
||
110 | |||
111 | /** |
||
112 | * Stop recording row specs for column autosizing. |
||
113 | * |
||
114 | * @return Writer |
||
115 | */ |
||
116 | public function disableCellAutosizing() |
||
121 | |||
122 | /** |
||
123 | * Add multiple rows at once. |
||
124 | * |
||
125 | * @param array|\Traversable $rows |
||
126 | * @param Style $style |
||
127 | * @throws \InvalidArgumentException |
||
128 | */ |
||
129 | public function addRows($rows, Style $style = null) |
||
139 | |||
140 | /** |
||
141 | * Add a single new row to the sheet and supply an optional style. |
||
142 | * |
||
143 | * @param array $row |
||
144 | * @param Style $style |
||
145 | */ |
||
146 | public function addRow(array $row, Style $style = null) |
||
154 | |||
155 | /** |
||
156 | * Wrap things up and write xlsx. |
||
157 | * |
||
158 | * @param string $fileName |
||
159 | */ |
||
160 | public function writeToFile($fileName = 'report.xlsx') |
||
166 | |||
167 | /** |
||
168 | * Wrap things up and send xlsx to browser. |
||
169 | * |
||
170 | * @param string $fileName |
||
171 | */ |
||
172 | public function writeToBrowser($fileName = 'report.xlsx') |
||
179 | |||
180 | /** |
||
181 | * Send headers for browser output. |
||
182 | * |
||
183 | * @param string $fileName |
||
184 | */ |
||
185 | private function sendHeaders($fileName) |
||
194 | |||
195 | /** |
||
196 | * Return array of available fonts & paths as key value pairs. |
||
197 | * |
||
198 | * @return array |
||
199 | */ |
||
200 | public function getFonts() |
||
204 | } |
||
205 |