1 | <?php |
||
18 | class Worksheet implements WorksheetInterface |
||
19 | { |
||
20 | /** @var \Box\Spout\Writer\Common\Sheet The "external" sheet */ |
||
21 | protected $externalSheet; |
||
22 | |||
23 | /** @var string Path to the XML file that will contain the sheet data */ |
||
24 | protected $worksheetFilePath; |
||
25 | |||
26 | /** @var \Box\Spout\Common\Escaper\ODS Strings escaper */ |
||
27 | protected $stringsEscaper; |
||
28 | |||
29 | /** @var \Box\Spout\Common\Helper\StringHelper To help with string manipulation */ |
||
30 | protected $stringHelper; |
||
31 | |||
32 | /** @var Resource Pointer to the temporary sheet data file (e.g. worksheets-temp/sheet1.xml) */ |
||
33 | protected $sheetFilePointer; |
||
34 | |||
35 | /** @var int Maximum number of columns among all the written rows */ |
||
36 | protected $maxNumColumns = 1; |
||
37 | |||
38 | /** @var int Index of the last written row */ |
||
39 | protected $lastWrittenRowIndex = 0; |
||
40 | |||
41 | /** |
||
42 | * @param \Box\Spout\Writer\Common\Sheet $externalSheet The associated "external" sheet |
||
43 | * @param string $worksheetFilesFolder Temporary folder where the files to create the XLSX will be stored |
||
44 | * @throws \Box\Spout\Common\Exception\IOException If the sheet data file cannot be opened for writing |
||
45 | */ |
||
46 | public function __construct($externalSheet, $worksheetFilesFolder) |
||
57 | |||
58 | /** |
||
59 | * Prepares the worksheet to accept data |
||
60 | * The XML file does not contain the "<table:table>" node as it contains the sheet's name |
||
61 | * which may change during the execution of the program. It will be added at the end. |
||
62 | * |
||
63 | * @return void |
||
64 | * @throws \Box\Spout\Common\Exception\IOException If the sheet data file cannot be opened for writing |
||
65 | */ |
||
66 | protected function startSheet() |
||
71 | |||
72 | /** |
||
73 | * Checks if the book has been created. Throws an exception if not created yet. |
||
74 | * |
||
75 | * @return void |
||
76 | * @throws \Box\Spout\Common\Exception\IOException If the sheet data file cannot be opened for writing |
||
77 | */ |
||
78 | protected function throwIfSheetFilePointerIsNotAvailable() |
||
84 | |||
85 | /** |
||
86 | * @return string Path to the temporary sheet content XML file |
||
87 | */ |
||
88 | public function getWorksheetFilePath() |
||
92 | |||
93 | /** |
||
94 | * Returns the table XML root node as string. |
||
95 | * |
||
96 | * @return string <table> node as string |
||
97 | */ |
||
98 | public function getTableElementStartAsString() |
||
108 | |||
109 | /** |
||
110 | * @return \Box\Spout\Writer\Common\Sheet The "external" sheet |
||
111 | */ |
||
112 | public function getExternalSheet() |
||
116 | |||
117 | /** |
||
118 | * @return int The index of the last written row |
||
119 | */ |
||
120 | public function getLastWrittenRowIndex() |
||
124 | |||
125 | /** |
||
126 | * Adds data to the worksheet. |
||
127 | * |
||
128 | * @param array $dataRow Array containing data to be written. Cannot be empty. |
||
129 | * Example $dataRow = ['data1', 1234, null, '', 'data5']; |
||
130 | * @param \Box\Spout\Writer\Style\Style $style Style to be applied to the row. NULL means use default style. |
||
131 | * @return void |
||
132 | * @throws \Box\Spout\Common\Exception\IOException If the data cannot be written |
||
133 | * @throws \Box\Spout\Common\Exception\InvalidArgumentException If a cell value's type is not supported |
||
134 | */ |
||
135 | public function addRow($dataRow, $style) |
||
176 | |||
177 | /** |
||
178 | * Returns the cell XML content, given its value. |
||
179 | * |
||
180 | * @param mixed $cellValue The value to be written |
||
181 | * @param int $styleIndex Index of the used style |
||
182 | * @param int $numTimesValueRepeated Number of times the value is consecutively repeated |
||
183 | * @return string The cell XML content |
||
184 | * @throws \Box\Spout\Common\Exception\InvalidArgumentException If a cell value's type is not supported |
||
185 | */ |
||
186 | protected function getCellContent($cellValue, $styleIndex, $numTimesValueRepeated) |
||
219 | |||
220 | /** |
||
221 | * Closes the worksheet |
||
222 | * |
||
223 | * @return void |
||
224 | */ |
||
225 | public function close() |
||
233 | } |
||
234 |