1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpOffice\PhpSpreadsheet\Writer\Ods; |
4
|
|
|
|
5
|
|
|
use PhpOffice\PhpSpreadsheet\Calculation\Calculation; |
6
|
|
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalculationException; |
7
|
|
|
use PhpOffice\PhpSpreadsheet\Cell\Cell; |
8
|
|
|
use PhpOffice\PhpSpreadsheet\Cell\Coordinate; |
9
|
|
|
use PhpOffice\PhpSpreadsheet\Cell\DataType; |
10
|
|
|
use PhpOffice\PhpSpreadsheet\Shared\XMLWriter; |
11
|
|
|
use PhpOffice\PhpSpreadsheet\Spreadsheet; |
12
|
|
|
use PhpOffice\PhpSpreadsheet\Worksheet\RowCellIterator; |
13
|
|
|
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet; |
14
|
|
|
use PhpOffice\PhpSpreadsheet\Writer\Ods; |
15
|
|
|
use PhpOffice\PhpSpreadsheet\Writer\Ods\Cell\Comment; |
16
|
|
|
use PhpOffice\PhpSpreadsheet\Writer\Ods\Cell\Style; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @author Alexander Pervakov <[email protected]> |
20
|
|
|
*/ |
21
|
|
|
class Content extends WriterPart |
22
|
|
|
{ |
23
|
|
|
const NUMBER_COLS_REPEATED_MAX = 1024; |
24
|
|
|
const NUMBER_ROWS_REPEATED_MAX = 1048576; |
25
|
|
|
|
26
|
|
|
private Formula $formulaConvertor; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Set parent Ods writer. |
30
|
|
|
*/ |
31
|
33 |
|
public function __construct(Ods $writer) |
32
|
|
|
{ |
33
|
33 |
|
parent::__construct($writer); |
34
|
|
|
|
35
|
33 |
|
$this->formulaConvertor = new Formula($this->getParentWriter()->getSpreadsheet()->getDefinedNames()); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Write content.xml to XML format. |
40
|
|
|
* |
41
|
|
|
* @return string XML Output |
42
|
|
|
*/ |
43
|
32 |
|
public function write(): string |
44
|
|
|
{ |
45
|
32 |
|
$objWriter = null; |
46
|
32 |
|
if ($this->getParentWriter()->getUseDiskCaching()) { |
47
|
|
|
$objWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); |
48
|
|
|
} else { |
49
|
32 |
|
$objWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
// XML header |
53
|
32 |
|
$objWriter->startDocument('1.0', 'UTF-8'); |
54
|
|
|
|
55
|
|
|
// Content |
56
|
32 |
|
$objWriter->startElement('office:document-content'); |
57
|
32 |
|
$objWriter->writeAttribute('xmlns:office', 'urn:oasis:names:tc:opendocument:xmlns:office:1.0'); |
58
|
32 |
|
$objWriter->writeAttribute('xmlns:style', 'urn:oasis:names:tc:opendocument:xmlns:style:1.0'); |
59
|
32 |
|
$objWriter->writeAttribute('xmlns:text', 'urn:oasis:names:tc:opendocument:xmlns:text:1.0'); |
60
|
32 |
|
$objWriter->writeAttribute('xmlns:table', 'urn:oasis:names:tc:opendocument:xmlns:table:1.0'); |
61
|
32 |
|
$objWriter->writeAttribute('xmlns:draw', 'urn:oasis:names:tc:opendocument:xmlns:drawing:1.0'); |
62
|
32 |
|
$objWriter->writeAttribute('xmlns:fo', 'urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0'); |
63
|
32 |
|
$objWriter->writeAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink'); |
64
|
32 |
|
$objWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/'); |
65
|
32 |
|
$objWriter->writeAttribute('xmlns:meta', 'urn:oasis:names:tc:opendocument:xmlns:meta:1.0'); |
66
|
32 |
|
$objWriter->writeAttribute('xmlns:number', 'urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0'); |
67
|
32 |
|
$objWriter->writeAttribute('xmlns:presentation', 'urn:oasis:names:tc:opendocument:xmlns:presentation:1.0'); |
68
|
32 |
|
$objWriter->writeAttribute('xmlns:svg', 'urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0'); |
69
|
32 |
|
$objWriter->writeAttribute('xmlns:chart', 'urn:oasis:names:tc:opendocument:xmlns:chart:1.0'); |
70
|
32 |
|
$objWriter->writeAttribute('xmlns:dr3d', 'urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0'); |
71
|
32 |
|
$objWriter->writeAttribute('xmlns:math', 'http://www.w3.org/1998/Math/MathML'); |
72
|
32 |
|
$objWriter->writeAttribute('xmlns:form', 'urn:oasis:names:tc:opendocument:xmlns:form:1.0'); |
73
|
32 |
|
$objWriter->writeAttribute('xmlns:script', 'urn:oasis:names:tc:opendocument:xmlns:script:1.0'); |
74
|
32 |
|
$objWriter->writeAttribute('xmlns:ooo', 'http://openoffice.org/2004/office'); |
75
|
32 |
|
$objWriter->writeAttribute('xmlns:ooow', 'http://openoffice.org/2004/writer'); |
76
|
32 |
|
$objWriter->writeAttribute('xmlns:oooc', 'http://openoffice.org/2004/calc'); |
77
|
32 |
|
$objWriter->writeAttribute('xmlns:dom', 'http://www.w3.org/2001/xml-events'); |
78
|
32 |
|
$objWriter->writeAttribute('xmlns:xforms', 'http://www.w3.org/2002/xforms'); |
79
|
32 |
|
$objWriter->writeAttribute('xmlns:xsd', 'http://www.w3.org/2001/XMLSchema'); |
80
|
32 |
|
$objWriter->writeAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance'); |
81
|
32 |
|
$objWriter->writeAttribute('xmlns:rpt', 'http://openoffice.org/2005/report'); |
82
|
32 |
|
$objWriter->writeAttribute('xmlns:of', 'urn:oasis:names:tc:opendocument:xmlns:of:1.2'); |
83
|
32 |
|
$objWriter->writeAttribute('xmlns:xhtml', 'http://www.w3.org/1999/xhtml'); |
84
|
32 |
|
$objWriter->writeAttribute('xmlns:grddl', 'http://www.w3.org/2003/g/data-view#'); |
85
|
32 |
|
$objWriter->writeAttribute('xmlns:tableooo', 'http://openoffice.org/2009/table'); |
86
|
32 |
|
$objWriter->writeAttribute('xmlns:field', 'urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0'); |
87
|
32 |
|
$objWriter->writeAttribute('xmlns:formx', 'urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0'); |
88
|
32 |
|
$objWriter->writeAttribute('xmlns:css3t', 'http://www.w3.org/TR/css3-text/'); |
89
|
32 |
|
$objWriter->writeAttribute('office:version', '1.2'); |
90
|
|
|
|
91
|
32 |
|
$objWriter->writeElement('office:scripts'); |
92
|
32 |
|
$objWriter->writeElement('office:font-face-decls'); |
93
|
|
|
|
94
|
|
|
// Styles XF |
95
|
32 |
|
$objWriter->startElement('office:automatic-styles'); |
96
|
32 |
|
$this->writeXfStyles($objWriter, $this->getParentWriter()->getSpreadsheet()); |
97
|
32 |
|
$objWriter->endElement(); |
98
|
|
|
|
99
|
32 |
|
$objWriter->startElement('office:body'); |
100
|
32 |
|
$objWriter->startElement('office:spreadsheet'); |
101
|
32 |
|
$objWriter->writeElement('table:calculation-settings'); |
102
|
|
|
|
103
|
32 |
|
$this->writeSheets($objWriter); |
104
|
|
|
|
105
|
32 |
|
(new AutoFilters($objWriter, $this->getParentWriter()->getSpreadsheet()))->write(); |
106
|
|
|
// Defined names (ranges and formulae) |
107
|
32 |
|
(new NamedExpressions($objWriter, $this->getParentWriter()->getSpreadsheet(), $this->formulaConvertor))->write(); |
108
|
|
|
|
109
|
32 |
|
$objWriter->endElement(); |
110
|
32 |
|
$objWriter->endElement(); |
111
|
32 |
|
$objWriter->endElement(); |
112
|
|
|
|
113
|
32 |
|
return $objWriter->getData(); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* Write sheets. |
118
|
|
|
*/ |
119
|
32 |
|
private function writeSheets(XMLWriter $objWriter): void |
120
|
|
|
{ |
121
|
32 |
|
$spreadsheet = $this->getParentWriter()->getSpreadsheet(); |
122
|
32 |
|
$sheetCount = $spreadsheet->getSheetCount(); |
123
|
32 |
|
for ($sheetIndex = 0; $sheetIndex < $sheetCount; ++$sheetIndex) { |
124
|
32 |
|
$spreadsheet->getSheet($sheetIndex)->calculateArrays($this->getParentWriter()->getPreCalculateFormulas()); |
125
|
32 |
|
$objWriter->startElement('table:table'); |
126
|
32 |
|
$objWriter->writeAttribute('table:name', $spreadsheet->getSheet($sheetIndex)->getTitle()); |
127
|
32 |
|
$objWriter->writeAttribute('table:style-name', Style::TABLE_STYLE_PREFIX . (string) ($sheetIndex + 1)); |
128
|
32 |
|
$objWriter->writeElement('office:forms'); |
129
|
32 |
|
$lastColumn = 0; |
130
|
5 |
|
foreach ($spreadsheet->getSheet($sheetIndex)->getColumnDimensions() as $columnDimension) { |
131
|
5 |
|
$thisColumn = $columnDimension->getColumnNumeric(); |
132
|
5 |
|
$emptyColumns = $thisColumn - $lastColumn - 1; |
133
|
4 |
|
if ($emptyColumns > 0) { |
134
|
4 |
|
$objWriter->startElement('table:table-column'); |
135
|
4 |
|
$objWriter->writeAttribute('table:number-columns-repeated', (string) $emptyColumns); |
136
|
|
|
$objWriter->endElement(); |
137
|
5 |
|
} |
138
|
5 |
|
$lastColumn = $thisColumn; |
139
|
5 |
|
$objWriter->startElement('table:table-column'); |
140
|
5 |
|
$objWriter->writeAttribute( |
141
|
5 |
|
'table:style-name', |
142
|
5 |
|
sprintf('%s_%d_%d', Style::COLUMN_STYLE_PREFIX, $sheetIndex, $columnDimension->getColumnNumeric()) |
143
|
5 |
|
); |
144
|
|
|
$objWriter->writeAttribute('table:default-cell-style-name', 'ce0'); |
145
|
5 |
|
// $objWriter->writeAttribute('table:number-columns-repeated', self::NUMBER_COLS_REPEATED_MAX); |
146
|
|
|
$objWriter->endElement(); |
147
|
32 |
|
} |
148
|
32 |
|
$this->writeRows($objWriter, $spreadsheet->getSheet($sheetIndex), $sheetIndex); |
149
|
|
|
$objWriter->endElement(); |
150
|
|
|
} |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* Write rows of the specified sheet. |
155
|
32 |
|
*/ |
156
|
|
|
private function writeRows(XMLWriter $objWriter, Worksheet $sheet, int $sheetIndex): void |
157
|
32 |
|
{ |
158
|
32 |
|
$numberRowsRepeated = self::NUMBER_ROWS_REPEATED_MAX; |
159
|
32 |
|
$span_row = 0; |
160
|
32 |
|
$rows = $sheet->getRowIterator(); |
161
|
32 |
|
foreach ($rows as $row) { |
162
|
32 |
|
$cellIterator = $row->getCellIterator(); |
163
|
32 |
|
--$numberRowsRepeated; |
164
|
32 |
|
if ($cellIterator->valid()) { |
165
|
32 |
|
$objWriter->startElement('table:table-row'); |
166
|
|
|
if ($span_row) { |
167
|
|
|
if ($span_row > 1) { |
168
|
|
|
$objWriter->writeAttribute('table:number-rows-repeated', (string) $span_row); |
169
|
|
|
} |
170
|
|
|
$objWriter->startElement('table:table-cell'); |
171
|
|
|
$objWriter->writeAttribute('table:number-columns-repeated', (string) self::NUMBER_COLS_REPEATED_MAX); |
172
|
|
|
$objWriter->endElement(); |
173
|
|
|
$span_row = 0; |
174
|
32 |
|
} else { |
175
|
|
|
if ($sheet->rowDimensionExists($row->getRowIndex()) && $sheet->getRowDimension($row->getRowIndex())->getRowHeight() > 0) { |
176
|
|
|
$objWriter->writeAttribute( |
177
|
|
|
'table:style-name', |
178
|
|
|
sprintf('%s_%d_%d', Style::ROW_STYLE_PREFIX, $sheetIndex, $row->getRowIndex()) |
179
|
|
|
); |
180
|
32 |
|
} |
181
|
|
|
$this->writeCells($objWriter, $cellIterator); |
182
|
32 |
|
} |
183
|
|
|
$objWriter->endElement(); |
184
|
|
|
} else { |
185
|
|
|
++$span_row; |
186
|
|
|
} |
187
|
|
|
} |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* Write cells of the specified row. |
192
|
32 |
|
*/ |
193
|
|
|
private function writeCells(XMLWriter $objWriter, RowCellIterator $cells): void |
194
|
32 |
|
{ |
195
|
32 |
|
$numberColsRepeated = self::NUMBER_COLS_REPEATED_MAX; |
196
|
32 |
|
$prevColumn = -1; |
197
|
|
|
foreach ($cells as $cell) { |
198
|
32 |
|
/** @var Cell $cell */ |
199
|
|
|
$column = Coordinate::columnIndexFromString($cell->getColumn()) - 1; |
200
|
32 |
|
$attributes = $cell->getFormulaAttributes() ?? []; |
201
|
32 |
|
|
202
|
32 |
|
$this->writeCellSpan($objWriter, $column, $prevColumn); |
203
|
|
|
$objWriter->startElement('table:table-cell'); |
204
|
|
|
$this->writeCellMerge($objWriter, $cell); |
205
|
32 |
|
|
206
|
32 |
|
// Style XF |
207
|
32 |
|
$style = $cell->getXfIndex(); |
208
|
|
|
if ($style !== null) { |
209
|
|
|
$objWriter->writeAttribute('table:style-name', Style::CELL_STYLE_PREFIX . $style); |
210
|
32 |
|
} |
211
|
|
|
|
212
|
3 |
|
switch ($cell->getDataType()) { |
213
|
3 |
|
case DataType::TYPE_BOOL: |
214
|
3 |
|
$objWriter->writeAttribute('office:value-type', 'boolean'); |
215
|
|
|
$objWriter->writeAttribute('office:boolean-value', $cell->getValue() ? 'true' : 'false'); |
216
|
3 |
|
$objWriter->writeElement('text:p', Calculation::getInstance()->getLocaleBoolean($cell->getValue() ? 'TRUE' : 'FALSE')); |
217
|
|
|
|
218
|
1 |
|
break; |
219
|
1 |
|
case DataType::TYPE_ERROR: |
220
|
1 |
|
$objWriter->writeAttribute('table:formula', 'of:=#NULL!'); |
221
|
1 |
|
$objWriter->writeAttribute('office:value-type', 'string'); |
222
|
|
|
$objWriter->writeAttribute('office:string-value', ''); |
223
|
1 |
|
$objWriter->writeElement('text:p', '#NULL!'); |
224
|
|
|
|
225
|
6 |
|
break; |
226
|
6 |
|
case DataType::TYPE_FORMULA: |
227
|
|
|
$formulaValue = $cell->getValueString(); |
228
|
5 |
|
if ($this->getParentWriter()->getPreCalculateFormulas()) { |
229
|
|
|
try { |
230
|
|
|
$formulaValue = $cell->getCalculatedValueString(); |
231
|
|
|
} catch (CalculationException $e) { |
232
|
|
|
// don't do anything |
233
|
6 |
|
} |
234
|
6 |
|
} |
235
|
4 |
|
if (isset($attributes['ref'])) { |
236
|
|
|
if (preg_match('/^([A-Z]{1,3})([0-9]{1,7})(:([A-Z]{1,3})([0-9]{1,7}))?$/', (string) $attributes['ref'], $matches) == 1) { |
237
|
2 |
|
$matrixRowSpan = 1; |
238
|
|
|
$matrixColSpan = 1; |
239
|
6 |
|
if (isset($matches[3])) { |
240
|
6 |
|
$minRow = (int) $matches[2]; |
241
|
|
|
$maxRow = (int) $matches[5]; |
242
|
6 |
|
$matrixRowSpan = $maxRow - $minRow + 1; |
243
|
|
|
$minCol = Coordinate::columnIndexFromString($matches[1]); |
244
|
13 |
|
$maxCol = Coordinate::columnIndexFromString($matches[4]); |
245
|
13 |
|
$matrixColSpan = $maxCol - $minCol + 1; |
246
|
13 |
|
} |
247
|
|
|
$objWriter->writeAttribute('table:number-matrix-columns-spanned', "$matrixColSpan"); |
248
|
13 |
|
$objWriter->writeAttribute('table:number-matrix-rows-spanned', "$matrixRowSpan"); |
249
|
|
|
} |
250
|
|
|
} |
251
|
|
|
$objWriter->writeAttribute('table:formula', $this->formulaConvertor->convertFormula($cell->getValueString())); |
252
|
18 |
|
if (is_numeric($formulaValue)) { |
253
|
18 |
|
$objWriter->writeAttribute('office:value-type', 'float'); |
254
|
18 |
|
} else { |
255
|
18 |
|
$objWriter->writeAttribute('office:value-type', 'string'); |
256
|
|
|
} |
257
|
1 |
|
$objWriter->writeAttribute('office:value', $formulaValue); |
258
|
1 |
|
$objWriter->writeElement('text:p', $formulaValue); |
259
|
1 |
|
|
260
|
1 |
|
break; |
261
|
1 |
|
case DataType::TYPE_NUMERIC: |
262
|
1 |
|
$objWriter->writeAttribute('office:value-type', 'float'); |
263
|
|
|
$objWriter->writeAttribute('office:value', $cell->getValueString()); |
264
|
1 |
|
$objWriter->writeElement('text:p', $cell->getValueString()); |
265
|
1 |
|
|
266
|
1 |
|
break; |
267
|
1 |
|
case DataType::TYPE_INLINE: |
268
|
1 |
|
// break intentionally omitted |
269
|
|
|
case DataType::TYPE_STRING: |
270
|
|
|
$objWriter->writeAttribute('office:value-type', 'string'); |
271
|
18 |
|
$url = $cell->getHyperlink()->getUrl(); |
272
|
|
|
if (empty($url)) { |
273
|
32 |
|
$objWriter->writeElement('text:p', $cell->getValueString()); |
274
|
32 |
|
} else { |
275
|
32 |
|
$objWriter->startElement('text:p'); |
276
|
|
|
$objWriter->startElement('text:a'); |
277
|
|
|
$sheets = 'sheet://'; |
278
|
32 |
|
$lensheets = strlen($sheets); |
279
|
32 |
|
if (substr($url, 0, $lensheets) === $sheets) { |
280
|
32 |
|
$url = '#' . substr($url, $lensheets); |
281
|
32 |
|
} |
282
|
32 |
|
$objWriter->writeAttribute('xlink:href', $url); |
283
|
32 |
|
$objWriter->writeAttribute('xlink:type', 'simple'); |
284
|
|
|
$objWriter->text($cell->getValueString()); |
285
|
|
|
$objWriter->endElement(); // text:a |
286
|
|
|
$objWriter->endElement(); // text:p |
287
|
|
|
} |
288
|
|
|
|
289
|
|
|
break; |
290
|
|
|
} |
291
|
|
|
Comment::write($objWriter, $cell); |
292
|
|
|
$objWriter->endElement(); |
293
|
32 |
|
$prevColumn = $column; |
294
|
|
|
} |
295
|
32 |
|
|
296
|
32 |
|
$numberColsRepeated = $numberColsRepeated - $prevColumn - 1; |
297
|
|
|
if ($numberColsRepeated > 0) { |
298
|
32 |
|
if ($numberColsRepeated > 1) { |
299
|
|
|
$objWriter->startElement('table:table-cell'); |
300
|
|
|
$objWriter->writeAttribute('table:number-columns-repeated', (string) $numberColsRepeated); |
301
|
|
|
$objWriter->endElement(); |
302
|
|
|
} else { |
303
|
|
|
$objWriter->writeElement('table:table-cell'); |
304
|
|
|
} |
305
|
|
|
} |
306
|
|
|
} |
307
|
|
|
|
308
|
32 |
|
/** |
309
|
|
|
* Write span. |
310
|
32 |
|
*/ |
311
|
|
|
private function writeCellSpan(XMLWriter $objWriter, int $curColumn, int $prevColumn): void |
312
|
32 |
|
{ |
313
|
32 |
|
$diff = $curColumn - $prevColumn - 1; |
314
|
32 |
|
if (1 === $diff) { |
315
|
32 |
|
$objWriter->writeElement('table:table-cell'); |
316
|
|
|
} elseif ($diff > 1) { |
317
|
32 |
|
$objWriter->startElement('table:table-cell'); |
318
|
32 |
|
$objWriter->writeAttribute('table:number-columns-repeated', (string) $diff); |
319
|
5 |
|
$objWriter->endElement(); |
320
|
5 |
|
} |
321
|
|
|
} |
322
|
|
|
|
323
|
|
|
/** |
324
|
32 |
|
* Write XF cell styles. |
325
|
32 |
|
*/ |
326
|
32 |
|
private function writeXfStyles(XMLWriter $writer, Spreadsheet $spreadsheet): void |
327
|
2 |
|
{ |
328
|
|
|
$styleWriter = new Style($writer); |
329
|
|
|
|
330
|
|
|
$sheetCount = $spreadsheet->getSheetCount(); |
331
|
|
|
for ($i = 0; $i < $sheetCount; ++$i) { |
332
|
|
|
$worksheet = $spreadsheet->getSheet($i); |
333
|
32 |
|
$styleWriter->writeTableStyle($worksheet, $i + 1); |
334
|
32 |
|
|
335
|
|
|
$worksheet->calculateColumnWidths(); |
336
|
|
|
foreach ($worksheet->getColumnDimensions() as $columnDimension) { |
337
|
|
|
if ($columnDimension->getWidth() !== -1.0) { |
338
|
|
|
$styleWriter->writeColumnStyles($columnDimension, $i); |
339
|
|
|
} |
340
|
|
|
} |
341
|
32 |
|
} |
342
|
|
|
for ($i = 0; $i < $sheetCount; ++$i) { |
343
|
32 |
|
$worksheet = $spreadsheet->getSheet($i); |
344
|
32 |
|
foreach ($worksheet->getRowDimensions() as $rowDimension) { |
345
|
|
|
if ($rowDimension->getRowHeight() > 0.0) { |
346
|
|
|
$styleWriter->writeRowStyles($rowDimension, $i); |
347
|
2 |
|
} |
348
|
2 |
|
} |
349
|
2 |
|
} |
350
|
2 |
|
|
351
|
2 |
|
foreach ($spreadsheet->getCellXfCollection() as $style) { |
352
|
2 |
|
$styleWriter->write($style); |
353
|
|
|
} |
354
|
2 |
|
} |
355
|
2 |
|
|
356
|
|
|
/** |
357
|
|
|
* Write attributes for merged cell. |
358
|
|
|
*/ |
359
|
|
|
private function writeCellMerge(XMLWriter $objWriter, Cell $cell): void |
360
|
|
|
{ |
361
|
|
|
if (!$cell->isMergeRangeValueCell()) { |
362
|
|
|
return; |
363
|
|
|
} |
364
|
|
|
|
365
|
|
|
$mergeRange = Coordinate::splitRange((string) $cell->getMergeRange()); |
366
|
|
|
[$startCell, $endCell] = $mergeRange[0]; |
367
|
|
|
$start = Coordinate::coordinateFromString($startCell); |
368
|
|
|
$end = Coordinate::coordinateFromString($endCell); |
369
|
|
|
$columnSpan = Coordinate::columnIndexFromString($end[0]) - Coordinate::columnIndexFromString($start[0]) + 1; |
370
|
|
|
$rowSpan = ((int) $end[1]) - ((int) $start[1]) + 1; |
371
|
|
|
|
372
|
|
|
$objWriter->writeAttribute('table:number-columns-spanned', (string) $columnSpan); |
373
|
|
|
$objWriter->writeAttribute('table:number-rows-spanned', (string) $rowSpan); |
374
|
|
|
} |
375
|
|
|
} |
376
|
|
|
|