Exemplo n.º 1
0
 /**
  * Write content file to XML format
  *
  * @param  \PhpOffice\PhpWord\PhpWord $phpWord
  * @return string XML Output
  */
 public function writeContent(PhpWord $phpWord = null)
 {
     if (is_null($phpWord)) {
         throw new Exception("No PhpWord assigned.");
     }
     $xmlWriter = $this->getXmlWriter();
     $xmlWriter->startDocument('1.0', 'UTF-8');
     $xmlWriter->startElement('office:document-content');
     $this->writeCommonRootAttributes($xmlWriter);
     $xmlWriter->writeAttribute('xmlns:xforms', 'http://www.w3.org/2002/xforms');
     $xmlWriter->writeAttribute('xmlns:xsd', 'http://www.w3.org/2001/XMLSchema');
     $xmlWriter->writeAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
     $xmlWriter->writeAttribute('xmlns:field', 'urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0');
     $xmlWriter->writeAttribute('xmlns:formx', 'urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0');
     $this->getAutomaticStyles($phpWord);
     $this->writeFontFaces($xmlWriter);
     // office:font-face-decls
     $this->writeAutomaticStyles($xmlWriter, $phpWord);
     // office:automatic-styles
     $xmlWriter->startElement('office:body');
     $xmlWriter->startElement('office:text');
     // text:sequence-decls
     $sequences = array('Illustration', 'Table', 'Text', 'Drawing');
     $xmlWriter->startElement('text:sequence-decls');
     foreach ($sequences as $sequence) {
         $xmlWriter->startElement('text:sequence-decl');
         $xmlWriter->writeAttribute('text:display-outline-level', 0);
         $xmlWriter->writeAttribute('text:name', $sequence);
         $xmlWriter->endElement();
     }
     $xmlWriter->endElement();
     // text:sequence-decl
     $sections = $phpWord->getSections();
     $sectionCount = count($sections);
     if ($sectionCount > 0) {
         foreach ($sections as $section) {
             $elements = $section->getElements();
             // $xmlWriter->startElement('text:section');
             foreach ($elements as $element) {
                 $elementWriter = new ElementWriter($xmlWriter, $this, $element, false);
                 $elementWriter->write();
             }
             // $xmlWriter->endElement(); // text:section
         }
     }
     $xmlWriter->endElement();
     // office:text
     $xmlWriter->endElement();
     // office:body
     $xmlWriter->endElement();
     // office:document-content
     return $xmlWriter->getData();
 }
Exemplo n.º 2
0
 /**
  * Write element
  */
 public function write()
 {
     $rows = $this->element->getRows();
     $rowCount = count($rows);
     $colCount = $this->element->countColumns();
     if ($rowCount > 0) {
         $this->xmlWriter->startElement('table:table');
         $this->xmlWriter->writeAttribute('table:name', $this->element->getElementId());
         $this->xmlWriter->writeAttribute('table:style', $this->element->getElementId());
         $this->xmlWriter->startElement('table:table-column');
         $this->xmlWriter->writeAttribute('table:number-columns-repeated', $colCount);
         $this->xmlWriter->endElement();
         // table:table-column
         foreach ($rows as $row) {
             $this->xmlWriter->startElement('table:table-row');
             foreach ($row->getCells() as $cell) {
                 $this->xmlWriter->startElement('table:table-cell');
                 $this->xmlWriter->writeAttribute('office:value-type', 'string');
                 $elements = $cell->getElements();
                 if (count($elements) > 0) {
                     foreach ($elements as $element) {
                         $elementWriter = new ElementWriter($this->xmlWriter, $this->parentWriter, $element);
                         $elementWriter->write();
                     }
                 } else {
                     $elementWriter = new ElementWriter($this->xmlWriter, $this->parentWriter, new TextBreakElement());
                     $elementWriter->write();
                 }
                 $this->xmlWriter->endElement();
                 // table:table-cell
             }
             $this->xmlWriter->endElement();
             // table:table-row
         }
         $this->xmlWriter->endElement();
         // table:table
     }
 }