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