1 | <?php |
||
27 | class WorksheetManager implements WorksheetManagerInterface |
||
28 | { |
||
29 | /** |
||
30 | * Maximum number of characters a cell can contain |
||
31 | * @see https://support.office.com/en-us/article/Excel-specifications-and-limits-16c69c74-3d6a-4aaf-ba35-e6eb276e8eaa [Excel 2007] |
||
32 | * @see https://support.office.com/en-us/article/Excel-specifications-and-limits-1672b34d-7043-467e-8e27-269d656771c3 [Excel 2010] |
||
33 | * @see https://support.office.com/en-us/article/Excel-specifications-and-limits-ca36e2dc-1f09-4620-b726-67c00b05040f [Excel 2013/2016] |
||
34 | */ |
||
35 | const MAX_CHARACTERS_PER_CELL = 32767; |
||
36 | |||
37 | const SHEET_XML_FILE_HEADER = <<<'EOD' |
||
38 | <?xml version="1.0" encoding="UTF-8" standalone="yes"?> |
||
39 | <worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"> |
||
40 | EOD; |
||
41 | |||
42 | /** @var bool Whether inline or shared strings should be used */ |
||
43 | protected $shouldUseInlineStrings; |
||
44 | |||
45 | /** @var RowManager Manages rows */ |
||
46 | private $rowManager; |
||
47 | |||
48 | /** @var StyleManager Manages styles */ |
||
49 | private $styleManager; |
||
50 | |||
51 | /** @var StyleMerger Helper to merge styles together */ |
||
52 | private $styleMerger; |
||
53 | |||
54 | /** @var SharedStringsManager Helper to write shared strings */ |
||
55 | private $sharedStringsManager; |
||
56 | |||
57 | /** @var XLSXEscaper Strings escaper */ |
||
58 | private $stringsEscaper; |
||
59 | |||
60 | /** @var StringHelper String helper */ |
||
61 | private $stringHelper; |
||
62 | |||
63 | /** @var InternalEntityFactory Factory to create entities */ |
||
64 | private $entityFactory; |
||
65 | |||
66 | /** |
||
67 | * WorksheetManager constructor. |
||
68 | * |
||
69 | * @param OptionsManagerInterface $optionsManager |
||
70 | * @param RowManager $rowManager |
||
71 | * @param StyleManager $styleManager |
||
72 | * @param StyleMerger $styleMerger |
||
73 | * @param SharedStringsManager $sharedStringsManager |
||
74 | * @param XLSXEscaper $stringsEscaper |
||
75 | * @param StringHelper $stringHelper |
||
76 | * @param InternalEntityFactory $entityFactory |
||
77 | 42 | */ |
|
78 | public function __construct( |
||
97 | |||
98 | /** |
||
99 | * @return SharedStringsManager |
||
100 | 38 | */ |
|
101 | public function getSharedStringsManager() |
||
105 | |||
106 | /** |
||
107 | * {@inheritdoc} |
||
108 | 42 | */ |
|
109 | public function startSheet(Worksheet $worksheet) |
||
119 | |||
120 | /** |
||
121 | * Checks if the sheet has been sucessfully created. Throws an exception if not. |
||
122 | * |
||
123 | * @param bool|resource $sheetFilePointer Pointer to the sheet data file or FALSE if unable to open the file |
||
124 | * @throws IOException If the sheet data file cannot be opened for writing |
||
125 | * @return void |
||
126 | 42 | */ |
|
127 | private function throwIfSheetFilePointerIsNotAvailable($sheetFilePointer) |
||
133 | |||
134 | /** |
||
135 | * {@inheritdoc} |
||
136 | 35 | */ |
|
137 | public function addRow(Worksheet $worksheet, Row $row) |
||
145 | |||
146 | /** |
||
147 | * Adds non empty row to the worksheet. |
||
148 | * |
||
149 | * @param Worksheet $worksheet The worksheet to add the row to |
||
150 | * @param Row $row The row to be written |
||
151 | * @throws IOException If the data cannot be written |
||
152 | * @throws InvalidArgumentException If a cell value's type is not supported |
||
153 | * @return void |
||
154 | 35 | */ |
|
155 | private function addNonEmptyRow(Worksheet $worksheet, Row $row) |
||
179 | |||
180 | /** |
||
181 | * Applies styles to the given style, merging the cell's style with its row's style |
||
182 | * |
||
183 | * @param Cell $cell |
||
184 | * @param Style $rowStyle |
||
185 | * |
||
186 | 35 | * @throws InvalidArgumentException If the given value cannot be processed |
|
187 | * @return RegisteredStyle |
||
188 | */ |
||
189 | 35 | private function applyStyleAndRegister(Cell $cell, Style $rowStyle) : RegisteredStyle |
|
220 | 2 | ||
221 | 5 | /** |
|
222 | * Builds and returns xml for a single cell. |
||
223 | 1 | * |
|
224 | 4 | * @param int $rowIndexOneBased |
|
225 | 2 | * @param int $columnIndexZeroBased |
|
226 | 1 | * @param Cell $cell |
|
227 | * @param int $styleId |
||
228 | * |
||
229 | * @throws InvalidArgumentException If the given value cannot be processed |
||
230 | 2 | * @return string |
|
231 | */ |
||
232 | private function getCellXML($rowIndexOneBased, $columnIndexZeroBased, Cell $cell, $styleId) |
||
261 | |||
262 | /** |
||
263 | * Returns the XML fragment for a cell containing a non empty string |
||
264 | * |
||
265 | 38 | * @param string $cellValue The cell value |
|
266 | * @throws InvalidArgumentException If the string exceeds the maximum number of characters allowed per cell |
||
267 | 38 | * @return string The XML fragment representing the cell |
|
268 | */ |
||
269 | 38 | private function getCellXMLFragmentForNonEmptyString($cellValue) |
|
284 | |||
285 | /** |
||
286 | * {@inheritdoc} |
||
287 | */ |
||
288 | public function close(Worksheet $worksheet) |
||
300 | } |
||
301 |