1 | <?php |
||
17 | class Worksheet implements WorksheetInterface |
||
18 | { |
||
19 | const SHEET_XML_FILE_HEADER = <<<EOD |
||
20 | <?xml version="1.0" encoding="UTF-8" standalone="yes"?> |
||
21 | <worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"> |
||
22 | EOD; |
||
23 | |||
24 | /** @var \Box\Spout\Writer\Common\Sheet The "external" sheet */ |
||
25 | protected $externalSheet; |
||
26 | |||
27 | /** @var string Path to the XML file that will contain the sheet data */ |
||
28 | protected $worksheetFilePath; |
||
29 | |||
30 | /** @var \Box\Spout\Writer\XLSX\Helper\SharedStringsHelper Helper to write shared strings */ |
||
31 | protected $sharedStringsHelper; |
||
32 | |||
33 | /** @var \Box\Spout\Writer\XLSX\Helper\StyleHelper Helper to work with styles */ |
||
34 | protected $styleHelper; |
||
35 | |||
36 | /** @var bool Whether inline or shared strings should be used */ |
||
37 | protected $shouldUseInlineStrings; |
||
38 | |||
39 | /** @var \Box\Spout\Common\Escaper\XLSX Strings escaper */ |
||
40 | protected $stringsEscaper; |
||
41 | |||
42 | /** @var Resource Pointer to the sheet data file (e.g. xl/worksheets/sheet1.xml) */ |
||
43 | protected $sheetFilePointer; |
||
44 | |||
45 | /** @var int Index of the last written row */ |
||
46 | protected $lastWrittenRowIndex = 0; |
||
47 | |||
48 | /** |
||
49 | * @param \Box\Spout\Writer\Common\Sheet $externalSheet The associated "external" sheet |
||
50 | * @param string $worksheetFilesFolder Temporary folder where the files to create the XLSX will be stored |
||
51 | * @param \Box\Spout\Writer\XLSX\Helper\SharedStringsHelper $sharedStringsHelper Helper for shared strings |
||
52 | * @param \Box\Spout\Writer\XLSX\Helper\StyleHelper Helper to work with styles |
||
53 | * @param bool $shouldUseInlineStrings Whether inline or shared strings should be used |
||
54 | * @throws \Box\Spout\Common\Exception\IOException If the sheet data file cannot be opened for writing |
||
55 | */ |
||
56 | 126 | public function __construct($externalSheet, $worksheetFilesFolder, $sharedStringsHelper, $styleHelper, $shouldUseInlineStrings) |
|
69 | |||
70 | /** |
||
71 | * Prepares the worksheet to accept data |
||
72 | * |
||
73 | * @return void |
||
74 | * @throws \Box\Spout\Common\Exception\IOException If the sheet data file cannot be opened for writing |
||
75 | */ |
||
76 | 126 | protected function startSheet() |
|
84 | |||
85 | /** |
||
86 | * Checks if the book has been created. Throws an exception if not created yet. |
||
87 | * |
||
88 | * @return void |
||
89 | * @throws \Box\Spout\Common\Exception\IOException If the sheet data file cannot be opened for writing |
||
90 | */ |
||
91 | 126 | protected function throwIfSheetFilePointerIsNotAvailable() |
|
97 | |||
98 | /** |
||
99 | * @return \Box\Spout\Writer\Common\Sheet The "external" sheet |
||
100 | */ |
||
101 | 99 | public function getExternalSheet() |
|
105 | |||
106 | /** |
||
107 | * @return int The index of the last written row |
||
108 | */ |
||
109 | 90 | public function getLastWrittenRowIndex() |
|
113 | |||
114 | /** |
||
115 | * @return int The ID of the worksheet |
||
116 | */ |
||
117 | 96 | public function getId() |
|
122 | |||
123 | /** |
||
124 | * Adds data to the worksheet. |
||
125 | * |
||
126 | * @param array $dataRow Array containing data to be written. Cannot be empty. |
||
127 | * Example $dataRow = ['data1', 1234, null, '', 'data5']; |
||
128 | * @param \Box\Spout\Writer\Style\Style $style Style to be applied to the row. NULL means use default style. |
||
129 | * @return void |
||
130 | * @throws \Box\Spout\Common\Exception\IOException If the data cannot be written |
||
131 | * @throws \Box\Spout\Common\Exception\InvalidArgumentException If a cell value's type is not supported |
||
132 | */ |
||
133 | 90 | public function addRow($dataRow, $style) |
|
141 | |||
142 | /** |
||
143 | * Returns whether the given row is empty |
||
144 | * |
||
145 | * @param array $dataRow Array containing data to be written. Cannot be empty. |
||
146 | * Example $dataRow = ['data1', 1234, null, '', 'data5']; |
||
147 | * @return bool Whether the given row is empty |
||
148 | */ |
||
149 | 90 | private function isEmptyRow($dataRow) |
|
154 | |||
155 | /** |
||
156 | * Adds non empty row to the worksheet. |
||
157 | * |
||
158 | * @param array $dataRow Array containing data to be written. Cannot be empty. |
||
159 | * Example $dataRow = ['data1', 1234, null, '', 'data5']; |
||
160 | * @param \Box\Spout\Writer\Style\Style $style Style to be applied to the row. NULL means use default style. |
||
161 | * @return void |
||
162 | * @throws \Box\Spout\Common\Exception\IOException If the data cannot be written |
||
163 | * @throws \Box\Spout\Common\Exception\InvalidArgumentException If a cell value's type is not supported |
||
164 | */ |
||
165 | 90 | private function addNonEmptyRow($dataRow, $style) |
|
185 | |||
186 | /** |
||
187 | * Build and return xml for a single cell. |
||
188 | * |
||
189 | * @param int $rowIndex |
||
190 | * @param int $cellNumber |
||
191 | * @param mixed $cellValue |
||
192 | * @param int $styleId |
||
193 | * @return string |
||
194 | * @throws InvalidArgumentException |
||
195 | */ |
||
196 | 90 | private function getCellXML($rowIndex, $cellNumber, $cellValue, $styleId) |
|
227 | |||
228 | /** |
||
229 | * Closes the worksheet |
||
230 | * |
||
231 | * @return void |
||
232 | */ |
||
233 | 96 | public function close() |
|
243 | } |
||
244 |