1 | <?php |
||
24 | class WorksheetManager implements WorksheetManagerInterface |
||
25 | { |
||
26 | /** |
||
27 | * Maximum number of characters a cell can contain |
||
28 | * @see https://support.office.com/en-us/article/Excel-specifications-and-limits-16c69c74-3d6a-4aaf-ba35-e6eb276e8eaa [Excel 2007] |
||
29 | * @see https://support.office.com/en-us/article/Excel-specifications-and-limits-1672b34d-7043-467e-8e27-269d656771c3 [Excel 2010] |
||
30 | * @see https://support.office.com/en-us/article/Excel-specifications-and-limits-ca36e2dc-1f09-4620-b726-67c00b05040f [Excel 2013/2016] |
||
31 | */ |
||
32 | const MAX_CHARACTERS_PER_CELL = 32767; |
||
33 | |||
34 | const SHEET_XML_FILE_HEADER = <<<EOD |
||
35 | <?xml version="1.0" encoding="UTF-8" standalone="yes"?> |
||
36 | <worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"> |
||
37 | EOD; |
||
38 | |||
39 | /** @var bool Whether inline or shared strings should be used */ |
||
40 | protected $shouldUseInlineStrings; |
||
41 | |||
42 | /** @var SharedStringsHelper Helper to write shared strings */ |
||
43 | private $sharedStringsHelper; |
||
44 | |||
45 | /** @var StyleHelper Helper to work with styles */ |
||
46 | private $styleHelper; |
||
47 | |||
48 | /** @var \Box\Spout\Common\Escaper\XLSX Strings escaper */ |
||
49 | private $stringsEscaper; |
||
50 | |||
51 | /** @var StringHelper String helper */ |
||
52 | private $stringHelper; |
||
53 | |||
54 | /** |
||
55 | * WorksheetManager constructor. |
||
56 | * |
||
57 | * @param OptionsManagerInterface $optionsManager |
||
58 | * @param SharedStringsHelper $sharedStringsHelper |
||
59 | * @param StyleHelper $styleHelper |
||
60 | * @param \Box\Spout\Common\Escaper\XLSX $stringsEscaper |
||
61 | * @param StringHelper $stringHelper |
||
62 | */ |
||
63 | 46 | public function __construct( |
|
76 | |||
77 | /** |
||
78 | * @return SharedStringsHelper |
||
79 | */ |
||
80 | 36 | public function getSharedStringsHelper() |
|
84 | |||
85 | |||
86 | /** |
||
87 | * Prepares the worksheet to accept data |
||
88 | * |
||
89 | * @param Worksheet $worksheet The worksheet to start |
||
90 | * @return void |
||
91 | * @throws \Box\Spout\Common\Exception\IOException If the sheet data file cannot be opened for writing |
||
92 | */ |
||
93 | 46 | public function startSheet(Worksheet $worksheet) |
|
103 | |||
104 | /** |
||
105 | * Checks if the sheet has been sucessfully created. Throws an exception if not. |
||
106 | * |
||
107 | * @param bool|resource $sheetFilePointer Pointer to the sheet data file or FALSE if unable to open the file |
||
108 | * @return void |
||
109 | * @throws IOException If the sheet data file cannot be opened for writing |
||
110 | */ |
||
111 | 46 | private function throwIfSheetFilePointerIsNotAvailable($sheetFilePointer) |
|
117 | |||
118 | /** |
||
119 | * Adds a row to the worksheet. |
||
120 | * |
||
121 | * @param Worksheet $worksheet The worksheet to add the row to |
||
122 | * @param Row $row The row to be added |
||
123 | * @return void |
||
124 | * |
||
125 | * @throws IOException If the data cannot be written |
||
126 | * @throws InvalidArgumentException If a cell value's type is not supported |
||
127 | */ |
||
128 | 33 | public function addRow(Worksheet $worksheet, Row $row) |
|
136 | |||
137 | /** |
||
138 | * Adds non empty row to the worksheet. |
||
139 | * |
||
140 | * @param Row $row The row to be written |
||
141 | * @return void |
||
142 | * |
||
143 | * @throws \Box\Spout\Common\Exception\IOException If the data cannot be written |
||
144 | * @throws \Box\Spout\Common\Exception\InvalidArgumentException If a cell value's type is not supported |
||
145 | */ |
||
146 | 33 | private function addNonEmptyRow(Worksheet $worksheet, Row $row) |
|
171 | |||
172 | /** |
||
173 | * Build and return xml for a single cell. |
||
174 | * |
||
175 | * @param int $rowIndex |
||
176 | * @param int $cellNumber |
||
177 | * @param Cell $cell |
||
178 | * @param int $styleId |
||
179 | * @return string |
||
180 | * @throws InvalidArgumentException If the given value cannot be processed |
||
181 | */ |
||
182 | 33 | private function getCellXML($rowIndex, $cellNumber, Cell $cell, $styleId) |
|
208 | |||
209 | /** |
||
210 | * Returns the XML fragment for a cell containing a non empty string |
||
211 | * |
||
212 | * @param string $cellValue The cell value |
||
213 | * @return string The XML fragment representing the cell |
||
214 | * @throws InvalidArgumentException If the string exceeds the maximum number of characters allowed per cell |
||
215 | */ |
||
216 | 32 | private function getCellXMLFragmentForNonEmptyString($cellValue) |
|
231 | |||
232 | /** |
||
233 | * Closes the worksheet |
||
234 | * |
||
235 | * @param Worksheet $worksheet |
||
236 | * @return void |
||
237 | */ |
||
238 | 36 | public function close(Worksheet $worksheet) |
|
250 | } |