1 | <?php |
||
16 | class Sheet |
||
17 | { |
||
18 | /** |
||
19 | * @var CellBuilder |
||
20 | */ |
||
21 | private $cellBuilder; |
||
22 | |||
23 | /** |
||
24 | * @var SizeCalculator |
||
25 | */ |
||
26 | private $sizeCalculator; |
||
27 | |||
28 | /** |
||
29 | * @var bool |
||
30 | */ |
||
31 | private $useCellAutosizing = false; |
||
32 | |||
33 | /** |
||
34 | * @var int |
||
35 | */ |
||
36 | private $freezePaneCellId; |
||
37 | |||
38 | /** |
||
39 | * Track next row index. |
||
40 | * |
||
41 | * @var int |
||
42 | */ |
||
43 | private $rowIndex = 1; |
||
44 | |||
45 | /** |
||
46 | * Holds width/column count of the widest row. |
||
47 | * |
||
48 | * @var int |
||
49 | */ |
||
50 | private $maxColumnCount; |
||
51 | |||
52 | /** |
||
53 | * Holds widths of the widest cells for column sizing. |
||
54 | * |
||
55 | * @var array |
||
56 | */ |
||
57 | private $columnWidths = array(); |
||
58 | |||
59 | /** |
||
60 | * Holds minimum allowed column width. |
||
61 | * |
||
62 | * @var float|int |
||
63 | */ |
||
64 | private $minColumnWidth = 0; |
||
65 | |||
66 | /** |
||
67 | * Holds maximum allowed column width. 254.86 appears |
||
68 | * to be the default maximum width. |
||
69 | * |
||
70 | * @var float|int |
||
71 | */ |
||
72 | private $maxColumnWidth = 254.86; |
||
73 | |||
74 | /** |
||
75 | * Sheet constructor. |
||
76 | * |
||
77 | * @param CellBuilder $cellBuilder |
||
78 | * @param SizeCalculator $sizeCalculator |
||
79 | */ |
||
80 | 15 | public function __construct(CellBuilder $cellBuilder, SizeCalculator $sizeCalculator) |
|
85 | |||
86 | /** |
||
87 | * Enable cell autosizing (~30-100% performance hit!). |
||
88 | */ |
||
89 | 6 | public function enableCellAutosizing() |
|
93 | |||
94 | /** |
||
95 | * Disable cell autosizing (default). |
||
96 | */ |
||
97 | 2 | public function disableCellAutosizing() |
|
101 | |||
102 | /** |
||
103 | * @param string $cellId |
||
104 | */ |
||
105 | 2 | public function setFreezePaneCellId($cellId) |
|
109 | |||
110 | /** |
||
111 | * Set custom column widths with 0 representing the first column. |
||
112 | * |
||
113 | * @param array $columnWidths |
||
114 | * @throws \InvalidArgumentException |
||
115 | */ |
||
116 | 4 | public function setFixedColumnWidths(array $columnWidths) |
|
126 | |||
127 | /** |
||
128 | * Set lower and/or upper limits for column widths. |
||
129 | * |
||
130 | * @param float|null $minWidth |
||
131 | * @param float|null $maxWidth |
||
132 | */ |
||
133 | 2 | public function setColumnWidthLimits($minWidth = null, $maxWidth = null) |
|
138 | |||
139 | /** |
||
140 | * Return array containing all column widths, limited to min or max |
||
141 | * column width, if one or both of them are set. |
||
142 | * |
||
143 | * @return array |
||
144 | */ |
||
145 | 5 | public function getColumnWidths() |
|
157 | |||
158 | /** |
||
159 | * Add single row and style to sheet. |
||
160 | * |
||
161 | * @param array $row |
||
162 | * @param Style $style |
||
163 | * |
||
164 | * @return string |
||
165 | */ |
||
166 | 5 | public function addRow(array $row, Style $style) |
|
174 | |||
175 | /** |
||
176 | * Track column count for dimensions xml (e.g. A1:K123). |
||
177 | * |
||
178 | * @param int $columnCount |
||
179 | */ |
||
180 | 5 | private function updateMaxColumnCount($columnCount) |
|
186 | |||
187 | /** |
||
188 | * Build and return xml string for single row. |
||
189 | * |
||
190 | * @param int $columnCount |
||
191 | * @param string $cellXml |
||
192 | * @return string |
||
193 | */ |
||
194 | 5 | private function getRowXml($columnCount, $cellXml) |
|
198 | |||
199 | /** |
||
200 | * Build and return xml string for single cell and update cell widths. |
||
201 | * |
||
202 | * @param array $row |
||
203 | * @param Style $style |
||
204 | * @return string |
||
205 | */ |
||
206 | 5 | private function getCellXml(array $row, Style $style) |
|
218 | |||
219 | /** |
||
220 | * Track cell width for column width sizing if its enabled. |
||
221 | * |
||
222 | * @param mixed $value |
||
223 | * @param int $cellIndex |
||
224 | * @param Font $font |
||
225 | */ |
||
226 | 5 | private function updateColumnWidths($value, $cellIndex, Font $font) |
|
237 | |||
238 | /** |
||
239 | * Return <dimension> xml string. |
||
240 | * |
||
241 | * @return string |
||
242 | */ |
||
243 | 1 | public function getDimensionXml() |
|
249 | |||
250 | /** |
||
251 | * Return <sheetViews> xml containing the freeze pane. |
||
252 | * |
||
253 | * @return string |
||
254 | */ |
||
255 | 2 | public function getSheetViewsXml() |
|
263 | |||
264 | /** |
||
265 | * Return <cols> xml for column widths or an empty string, |
||
266 | * if there are no column widths. |
||
267 | * Format widths to account for locales with comma as decimal point. |
||
268 | * |
||
269 | * @return string |
||
270 | */ |
||
271 | 1 | public function getColsXml() |
|
286 | |||
287 | /** |
||
288 | * Return array of available font names and paths. |
||
289 | * |
||
290 | * @return array |
||
291 | */ |
||
292 | public function getFonts() |
||
296 | } |
||
297 |
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.