32 parent::__construct($writer);
48 $objWriter =
new XMLWriter(XMLWriter::STORAGE_MEMORY);
52 $objWriter->startDocument(
'1.0',
'UTF-8');
55 $objWriter->startElement(
'office:document-content');
56 $objWriter->writeAttribute(
'xmlns:office',
'urn:oasis:names:tc:opendocument:xmlns:office:1.0');
57 $objWriter->writeAttribute(
'xmlns:style',
'urn:oasis:names:tc:opendocument:xmlns:style:1.0');
58 $objWriter->writeAttribute(
'xmlns:text',
'urn:oasis:names:tc:opendocument:xmlns:text:1.0');
59 $objWriter->writeAttribute(
'xmlns:table',
'urn:oasis:names:tc:opendocument:xmlns:table:1.0');
60 $objWriter->writeAttribute(
'xmlns:draw',
'urn:oasis:names:tc:opendocument:xmlns:drawing:1.0');
61 $objWriter->writeAttribute(
'xmlns:fo',
'urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0');
62 $objWriter->writeAttribute(
'xmlns:xlink',
'http://www.w3.org/1999/xlink');
63 $objWriter->writeAttribute(
'xmlns:dc',
'http://purl.org/dc/elements/1.1/');
64 $objWriter->writeAttribute(
'xmlns:meta',
'urn:oasis:names:tc:opendocument:xmlns:meta:1.0');
65 $objWriter->writeAttribute(
'xmlns:number',
'urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0');
66 $objWriter->writeAttribute(
'xmlns:presentation',
'urn:oasis:names:tc:opendocument:xmlns:presentation:1.0');
67 $objWriter->writeAttribute(
'xmlns:svg',
'urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0');
68 $objWriter->writeAttribute(
'xmlns:chart',
'urn:oasis:names:tc:opendocument:xmlns:chart:1.0');
69 $objWriter->writeAttribute(
'xmlns:dr3d',
'urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0');
70 $objWriter->writeAttribute(
'xmlns:math',
'http://www.w3.org/1998/Math/MathML');
71 $objWriter->writeAttribute(
'xmlns:form',
'urn:oasis:names:tc:opendocument:xmlns:form:1.0');
72 $objWriter->writeAttribute(
'xmlns:script',
'urn:oasis:names:tc:opendocument:xmlns:script:1.0');
73 $objWriter->writeAttribute(
'xmlns:ooo',
'http://openoffice.org/2004/office');
74 $objWriter->writeAttribute(
'xmlns:ooow',
'http://openoffice.org/2004/writer');
75 $objWriter->writeAttribute(
'xmlns:oooc',
'http://openoffice.org/2004/calc');
76 $objWriter->writeAttribute(
'xmlns:dom',
'http://www.w3.org/2001/xml-events');
77 $objWriter->writeAttribute(
'xmlns:xforms',
'http://www.w3.org/2002/xforms');
78 $objWriter->writeAttribute(
'xmlns:xsd',
'http://www.w3.org/2001/XMLSchema');
79 $objWriter->writeAttribute(
'xmlns:xsi',
'http://www.w3.org/2001/XMLSchema-instance');
80 $objWriter->writeAttribute(
'xmlns:rpt',
'http://openoffice.org/2005/report');
81 $objWriter->writeAttribute(
'xmlns:of',
'urn:oasis:names:tc:opendocument:xmlns:of:1.2');
82 $objWriter->writeAttribute(
'xmlns:xhtml',
'http://www.w3.org/1999/xhtml');
83 $objWriter->writeAttribute(
'xmlns:grddl',
'http://www.w3.org/2003/g/data-view#');
84 $objWriter->writeAttribute(
'xmlns:tableooo',
'http://openoffice.org/2009/table');
85 $objWriter->writeAttribute(
'xmlns:field',
'urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0');
86 $objWriter->writeAttribute(
'xmlns:formx',
'urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0');
87 $objWriter->writeAttribute(
'xmlns:css3t',
'http://www.w3.org/TR/css3-text/');
88 $objWriter->writeAttribute(
'office:version',
'1.2');
90 $objWriter->writeElement(
'office:scripts');
91 $objWriter->writeElement(
'office:font-face-decls');
94 $objWriter->startElement(
'office:automatic-styles');
96 $objWriter->endElement();
98 $objWriter->startElement(
'office:body');
99 $objWriter->startElement(
'office:spreadsheet');
100 $objWriter->writeElement(
'table:calculation-settings');
102 $this->writeSheets($objWriter);
108 $objWriter->endElement();
109 $objWriter->endElement();
110 $objWriter->endElement();
112 return $objWriter->getData();
118 private function writeSheets(
XMLWriter $objWriter):
void 121 $sheetCount = $spreadsheet->getSheetCount();
122 for (
$i = 0;
$i < $sheetCount; ++
$i) {
123 $objWriter->startElement(
'table:table');
124 $objWriter->writeAttribute(
'table:name', $spreadsheet->getSheet(
$i)->getTitle());
125 $objWriter->writeElement(
'office:forms');
126 $objWriter->startElement(
'table:table-column');
127 $objWriter->writeAttribute(
'table:number-columns-repeated', self::NUMBER_COLS_REPEATED_MAX);
128 $objWriter->endElement();
129 $this->
writeRows($objWriter, $spreadsheet->getSheet(
$i));
130 $objWriter->endElement();
139 $numberRowsRepeated = self::NUMBER_ROWS_REPEATED_MAX;
142 while (
$rows->valid()) {
143 --$numberRowsRepeated;
145 if (
$row->getCellIterator()->valid()) {
147 $objWriter->startElement(
'table:table-row');
149 $objWriter->writeAttribute(
'table:number-rows-repeated', $span_row);
151 $objWriter->startElement(
'table:table-cell');
152 $objWriter->writeAttribute(
'table:number-columns-repeated', self::NUMBER_COLS_REPEATED_MAX);
153 $objWriter->endElement();
154 $objWriter->endElement();
157 $objWriter->startElement(
'table:table-row');
158 $this->writeCells($objWriter,
$row);
159 $objWriter->endElement();
172 $numberColsRepeated = self::NUMBER_COLS_REPEATED_MAX;
175 while ($cells->valid()) {
177 $cell = $cells->current();
181 $objWriter->startElement(
'table:table-cell');
185 $style = $cell->getXfIndex();
187 $objWriter->writeAttribute(
'table:style-name', Style::CELL_STYLE_PREFIX .
$style);
190 switch ($cell->getDataType()) {
192 $objWriter->writeAttribute(
'office:value-type',
'boolean');
193 $objWriter->writeAttribute(
'office:value', $cell->getValue());
194 $objWriter->writeElement(
'text:p', $cell->getValue());
198 $objWriter->writeAttribute(
'table:formula',
'of:=#NULL!');
199 $objWriter->writeAttribute(
'office:value-type',
'string');
200 $objWriter->writeAttribute(
'office:string-value',
'');
201 $objWriter->writeElement(
'text:p',
'#NULL!');
205 $formulaValue = $cell->getValue();
208 $formulaValue = $cell->getCalculatedValue();
213 $objWriter->writeAttribute(
'table:formula', $this->formulaConvertor->convertFormula($cell->getValue()));
214 if (is_numeric($formulaValue)) {
215 $objWriter->writeAttribute(
'office:value-type',
'float');
217 $objWriter->writeAttribute(
'office:value-type',
'string');
219 $objWriter->writeAttribute(
'office:value', $formulaValue);
220 $objWriter->writeElement(
'text:p', $formulaValue);
224 $objWriter->writeAttribute(
'office:value-type',
'float');
225 $objWriter->writeAttribute(
'office:value', $cell->getValue());
226 $objWriter->writeElement(
'text:p', $cell->getValue());
232 $objWriter->writeAttribute(
'office:value-type',
'string');
233 $objWriter->writeElement(
'text:p', $cell->getValue());
238 $objWriter->endElement();
239 $prevColumn = $column;
242 $numberColsRepeated = $numberColsRepeated - $prevColumn - 1;
243 if ($numberColsRepeated > 0) {
244 if ($numberColsRepeated > 1) {
245 $objWriter->startElement(
'table:table-cell');
246 $objWriter->writeAttribute(
'table:number-columns-repeated', $numberColsRepeated);
247 $objWriter->endElement();
249 $objWriter->writeElement(
'table:table-cell');
262 $diff = $curColumn - $prevColumn - 1;
264 $objWriter->writeElement(
'table:table-cell');
265 } elseif ($diff > 1) {
266 $objWriter->startElement(
'table:table-cell');
267 $objWriter->writeAttribute(
'table:number-columns-repeated', $diff);
268 $objWriter->endElement();
277 $styleWriter =
new Style($writer);
279 $styleWriter->write(
$style);
293 [$startCell, $endCell] = $mergeRange[0];
297 $rowSpan = ((int)
$end[1]) - ((int)
$start[1]) + 1;
299 $objWriter->writeAttribute(
'table:number-columns-spanned', $columnSpan);
300 $objWriter->writeAttribute(
'table:number-rows-spanned', $rowSpan);
static splitRange($pRange)
Split range into coordinate strings.
__construct(Ods $writer)
Set parent Ods writer.
getSpreadsheet()
Get Spreadsheet object.
writeRows(XMLWriter $objWriter, Worksheet $sheet)
Write rows of the specified sheet.
getRowIterator($startRow=1, $endRow=null)
Get row iterator.
getDiskCachingDirectory()
Get disk caching directory.
getCellXfCollection()
Get the workbook collection of cellXfs.
const NUMBER_COLS_REPEATED_MAX
getParentWriter()
Get Ods writer.
const NUMBER_ROWS_REPEATED_MAX
getPreCalculateFormulas()
Get Pre-Calculate Formulas flag If this is true (the default), then the writer will recalculate all f...
write()
Write content.xml to XML format.
writeCellMerge(XMLWriter $objWriter, Cell $cell)
Write attributes for merged cell.
writeXfStyles(XMLWriter $writer, Spreadsheet $spreadsheet)
Write XF cell styles.
static coordinateFromString($pCoordinateString)
Coordinate from string.
isMergeRangeValueCell()
Is this cell the master (top left cell) in a merge range (that holds the actual data value)...
getMergeRange()
If this cell is in a merge range, then return the range.
writeCellSpan(XMLWriter $objWriter, $curColumn, $prevColumn)
Write span.
getCellIterator($startColumn='A', $endColumn=null)
Get cell iterator.
getUseDiskCaching()
Get use disk caching where possible?
static columnIndexFromString($pString)
Column index from string.