ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
Content.php
Go to the documentation of this file.
1 <?php
38 {
40  const NUMBER_ROWS_REPEATED_MAX = 1048576;
41 
49  public function write(PHPExcel $pPHPExcel = null)
50  {
51  if (!$pPHPExcel) {
52  $pPHPExcel = $this->getParentWriter()->getPHPExcel(); /* @var $pPHPExcel PHPExcel */
53  }
54 
55  $objWriter = null;
56  if ($this->getParentWriter()->getUseDiskCaching()) {
58  } else {
60  }
61 
62  // XML header
63  $objWriter->startDocument('1.0', 'UTF-8');
64 
65  // Content
66  $objWriter->startElement('office:document-content');
67  $objWriter->writeAttribute('xmlns:office', 'urn:oasis:names:tc:opendocument:xmlns:office:1.0');
68  $objWriter->writeAttribute('xmlns:style', 'urn:oasis:names:tc:opendocument:xmlns:style:1.0');
69  $objWriter->writeAttribute('xmlns:text', 'urn:oasis:names:tc:opendocument:xmlns:text:1.0');
70  $objWriter->writeAttribute('xmlns:table', 'urn:oasis:names:tc:opendocument:xmlns:table:1.0');
71  $objWriter->writeAttribute('xmlns:draw', 'urn:oasis:names:tc:opendocument:xmlns:drawing:1.0');
72  $objWriter->writeAttribute('xmlns:fo', 'urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0');
73  $objWriter->writeAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink');
74  $objWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/');
75  $objWriter->writeAttribute('xmlns:meta', 'urn:oasis:names:tc:opendocument:xmlns:meta:1.0');
76  $objWriter->writeAttribute('xmlns:number', 'urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0');
77  $objWriter->writeAttribute('xmlns:presentation', 'urn:oasis:names:tc:opendocument:xmlns:presentation:1.0');
78  $objWriter->writeAttribute('xmlns:svg', 'urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0');
79  $objWriter->writeAttribute('xmlns:chart', 'urn:oasis:names:tc:opendocument:xmlns:chart:1.0');
80  $objWriter->writeAttribute('xmlns:dr3d', 'urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0');
81  $objWriter->writeAttribute('xmlns:math', 'http://www.w3.org/1998/Math/MathML');
82  $objWriter->writeAttribute('xmlns:form', 'urn:oasis:names:tc:opendocument:xmlns:form:1.0');
83  $objWriter->writeAttribute('xmlns:script', 'urn:oasis:names:tc:opendocument:xmlns:script:1.0');
84  $objWriter->writeAttribute('xmlns:ooo', 'http://openoffice.org/2004/office');
85  $objWriter->writeAttribute('xmlns:ooow', 'http://openoffice.org/2004/writer');
86  $objWriter->writeAttribute('xmlns:oooc', 'http://openoffice.org/2004/calc');
87  $objWriter->writeAttribute('xmlns:dom', 'http://www.w3.org/2001/xml-events');
88  $objWriter->writeAttribute('xmlns:xforms', 'http://www.w3.org/2002/xforms');
89  $objWriter->writeAttribute('xmlns:xsd', 'http://www.w3.org/2001/XMLSchema');
90  $objWriter->writeAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
91  $objWriter->writeAttribute('xmlns:rpt', 'http://openoffice.org/2005/report');
92  $objWriter->writeAttribute('xmlns:of', 'urn:oasis:names:tc:opendocument:xmlns:of:1.2');
93  $objWriter->writeAttribute('xmlns:xhtml', 'http://www.w3.org/1999/xhtml');
94  $objWriter->writeAttribute('xmlns:grddl', 'http://www.w3.org/2003/g/data-view#');
95  $objWriter->writeAttribute('xmlns:tableooo', 'http://openoffice.org/2009/table');
96  $objWriter->writeAttribute('xmlns:field', 'urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0');
97  $objWriter->writeAttribute('xmlns:formx', 'urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0');
98  $objWriter->writeAttribute('xmlns:css3t', 'http://www.w3.org/TR/css3-text/');
99  $objWriter->writeAttribute('office:version', '1.2');
100 
101  $objWriter->writeElement('office:scripts');
102  $objWriter->writeElement('office:font-face-decls');
103  $objWriter->writeElement('office:automatic-styles');
104 
105  $objWriter->startElement('office:body');
106  $objWriter->startElement('office:spreadsheet');
107  $objWriter->writeElement('table:calculation-settings');
108  $this->_writeSheets($objWriter);
109  $objWriter->writeElement('table:named-expressions');
110  $objWriter->endElement();
111  $objWriter->endElement();
112  $objWriter->endElement();
113 
114  return $objWriter->getData();
115  }
116 
123  {
124  $pPHPExcel = $this->getParentWriter()->getPHPExcel(); /* @var $pPHPExcel PHPExcel */
125 
126  $sheet_count = $pPHPExcel->getSheetCount();
127  for ($i = 0; $i < $sheet_count; $i++) {
128  //$this->getWriterPart('Worksheet')->writeWorksheet());
129  $objWriter->startElement('table:table');
130  $objWriter->writeAttribute('table:name', $pPHPExcel->getSheet($i)->getTitle());
131  $objWriter->writeElement('office:forms');
132  $objWriter->startElement('table:table-column');
133  $objWriter->writeAttribute('table:number-columns-repeated', self::NUMBER_COLS_REPEATED_MAX);
134  $objWriter->endElement();
135  $this->_writeRows($objWriter, $pPHPExcel->getSheet($i));
136  $objWriter->endElement();
137  }
138  }
139 
147  {
148  $number_rows_repeated = self::NUMBER_ROWS_REPEATED_MAX;
149  $span_row = 0;
150  $rows = $sheet->getRowIterator();
151  while ($rows->valid()) {
152  $number_rows_repeated--;
153  $row = $rows->current();
154  if ($row->getCellIterator()->valid()) {
155  if ($span_row) {
156  $objWriter->startElement('table:table-row');
157  if ($span_row > 1) {
158  $objWriter->writeAttribute('table:number-rows-repeated', $span_row);
159  }
160  $objWriter->startElement('table:table-cell');
161  $objWriter->writeAttribute('table:number-columns-repeated', self::NUMBER_COLS_REPEATED_MAX);
162  $objWriter->endElement();
163  $objWriter->endElement();
164  $span_row = 0;
165  }
166  $objWriter->startElement('table:table-row');
167  $this->_writeCells($objWriter, $row);
168  $objWriter->endElement();
169  } else {
170  $span_row++;
171  }
172  $rows->next();
173  }
174  }
175 
184  {
185  $number_cols_repeated = self::NUMBER_COLS_REPEATED_MAX;
186  $prev_column = -1;
187  $cells = $row->getCellIterator();
188  while ($cells->valid()) {
189  $cell = $cells->current();
190  $column = PHPExcel_Cell::columnIndexFromString($cell->getColumn()) - 1;
191 
192  $this->_writeCellSpan($objWriter, $column, $prev_column);
193  $objWriter->startElement('table:table-cell');
194 
195  switch ($cell->getDataType()) {
197  $objWriter->writeAttribute('office:value-type', 'boolean');
198  $objWriter->writeAttribute('office:value', $cell->getValue());
199  $objWriter->writeElement('text:p', $cell->getValue());
200  break;
201 
203  throw new PHPExcel_Writer_Exception('Writing of error not implemented yet.');
204  break;
205 
207  try {
208  $formula_value = $cell->getCalculatedValue();
209  } catch (Exception $e) {
210  $formula_value = $cell->getValue();
211  }
212  $objWriter->writeAttribute('table:formula', 'of:' . $cell->getValue());
213  if (is_numeric($formula_value)) {
214  $objWriter->writeAttribute('office:value-type', 'float');
215  } else {
216  $objWriter->writeAttribute('office:value-type', 'string');
217  }
218  $objWriter->writeAttribute('office:value', $formula_value);
219  $objWriter->writeElement('text:p', $formula_value);
220  break;
221 
223  throw new PHPExcel_Writer_Exception('Writing of inline not implemented yet.');
224  break;
225 
227  $objWriter->writeAttribute('office:value-type', 'float');
228  $objWriter->writeAttribute('office:value', $cell->getValue());
229  $objWriter->writeElement('text:p', $cell->getValue());
230  break;
231 
233  $objWriter->writeAttribute('office:value-type', 'string');
234  $objWriter->writeElement('text:p', $cell->getValue());
235  break;
236  }
238  $objWriter->endElement();
239  $prev_column = $column;
240  $cells->next();
241  }
242  $number_cols_repeated = $number_cols_repeated - $prev_column - 1;
243  if ($number_cols_repeated > 0) {
244  if ($number_cols_repeated > 1) {
245  $objWriter->startElement('table:table-cell');
246  $objWriter->writeAttribute('table:number-columns-repeated', $number_cols_repeated);
247  $objWriter->endElement();
248  } else {
249  $objWriter->writeElement('table:table-cell');
250  }
251  }
252  }
253 
261  private function _writeCellSpan(PHPExcel_Shared_XMLWriter $objWriter, $curColumn, $prevColumn)
262  {
263  $diff = $curColumn - $prevColumn - 1;
264  if (1 === $diff) {
265  $objWriter->writeElement('table:table-cell');
266  } elseif ($diff > 1) {
267  $objWriter->startElement('table:table-cell');
268  $objWriter->writeAttribute('table:number-columns-repeated', $diff);
269  $objWriter->endElement();
270  }
271  }
272 }
_writeCells(PHPExcel_Shared_XMLWriter $objWriter, PHPExcel_Worksheet_Row $row)
Write cells of the specified row.
Definition: Content.php:183
getCellIterator($startColumn='A', $endColumn=null)
Get cell iterator.
Definition: Row.php:89
static write(PHPExcel_Shared_XMLWriter $objWriter, PHPExcel_Cell $cell)
Definition: Comment.php:39
_writeCellSpan(PHPExcel_Shared_XMLWriter $objWriter, $curColumn, $prevColumn)
Write span.
Definition: Content.php:261
getParentWriter()
Get parent IWriter object.
Definition: WriterPart.php:61
$objWriter
getRowIterator($startRow=1, $endRow=null)
Get row iterator.
Definition: Worksheet.php:2567
$column
Definition: 39dropdown.php:62
_writeSheets(PHPExcel_Shared_XMLWriter $objWriter)
Write sheets.
Definition: Content.php:122
_writeRows(PHPExcel_Shared_XMLWriter $objWriter, PHPExcel_Worksheet $sheet)
Write rows of the specified sheet.
Definition: Content.php:146
$rows
Definition: xhr_table.php:10
static columnIndexFromString($pString='A')
Column index from string.
Definition: Cell.php:782
$i
Definition: disco.tpl.php:19
const STORAGE_MEMORY
Temporary storage method.
Definition: XMLWriter.php:46
write(PHPExcel $pPHPExcel=null)
Write content.xml to XML format.
Definition: Content.php:49