当前位置: 首页>>代码示例>>PHP>>正文


PHP PHPWord::getSections方法代码示例

本文整理汇总了PHP中PHPWord::getSections方法的典型用法代码示例。如果您正苦于以下问题:PHP PHPWord::getSections方法的具体用法?PHP PHPWord::getSections怎么用?PHP PHPWord::getSections使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PHPWord的用法示例。


在下文中一共展示了PHPWord::getSections方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: writeDocument

 public function writeDocument(PHPWord $pPHPWord = null)
 {
     // Create XML writer
     if ($this->getParentWriter()->getUseDiskCaching()) {
         $objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
     } else {
         $objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_MEMORY);
     }
     // XML header
     $objWriter->startDocument('1.0', 'UTF-8', 'yes');
     // w:document
     $objWriter->startElement('w:document');
     $objWriter->writeAttribute('xmlns:ve', 'http://schemas.openxmlformats.org/markup-compatibility/2006');
     $objWriter->writeAttribute('xmlns:o', 'urn:schemas-microsoft-com:office:office');
     $objWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships');
     $objWriter->writeAttribute('xmlns:m', 'http://schemas.openxmlformats.org/officeDocument/2006/math');
     $objWriter->writeAttribute('xmlns:v', 'urn:schemas-microsoft-com:vml');
     $objWriter->writeAttribute('xmlns:wp', 'http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing');
     $objWriter->writeAttribute('xmlns:w10', 'urn:schemas-microsoft-com:office:word');
     $objWriter->writeAttribute('xmlns:w', 'http://schemas.openxmlformats.org/wordprocessingml/2006/main');
     $objWriter->writeAttribute('xmlns:wne', 'http://schemas.microsoft.com/office/word/2006/wordml');
     $objWriter->startElement('w:body');
     $_sections = $pPHPWord->getSections();
     $countSections = count($_sections);
     $pSection = 0;
     if ($countSections > 0) {
         foreach ($_sections as $section) {
             $pSection++;
             $_elements = $section->getElements();
             foreach ($_elements as $element) {
                 if ($element instanceof PHPWord_Section_Text) {
                     $this->_writeText($objWriter, $element);
                 } elseif ($element instanceof PHPWord_Section_TextRun) {
                     $this->_writeTextRun($objWriter, $element);
                 } elseif ($element instanceof PHPWord_Section_Link) {
                     $this->_writeLink($objWriter, $element);
                 } elseif ($element instanceof PHPWord_Section_Title) {
                     $this->_writeTitle($objWriter, $element);
                 } elseif ($element instanceof PHPWord_Section_TextBreak) {
                     $this->_writeTextBreak($objWriter);
                 } elseif ($element instanceof PHPWord_Section_PageBreak) {
                     $this->_writePageBreak($objWriter);
                 } elseif ($element instanceof PHPWord_Section_Table) {
                     $this->_writeTable($objWriter, $element);
                 } elseif ($element instanceof PHPWord_Section_ListItem) {
                     $this->_writeListItem($objWriter, $element);
                 } elseif ($element instanceof PHPWord_Section_Image || $element instanceof PHPWord_Section_MemoryImage) {
                     $this->_writeImage($objWriter, $element);
                 } elseif ($element instanceof PHPWord_Section_Object) {
                     $this->_writeObject($objWriter, $element);
                 } elseif ($element instanceof PHPWord_TOC) {
                     $this->_writeTOC($objWriter);
                 }
             }
             if ($pSection == $countSections) {
                 $this->_writeEndSection($objWriter, $section);
             } else {
                 $this->_writeSection($objWriter, $section);
             }
         }
     }
     $objWriter->endElement();
     // End w:body
     $objWriter->endElement();
     // End w:document
     // Return
     return $objWriter->getData();
 }
开发者ID:tmlsoft,项目名称:main,代码行数:68,代码来源:Document.php

示例2: writeContent

 /**
  * Write content file to XML format
  *
  * @param    PHPWord $pPHPWord
  * @return    string                        XML Output
  * @throws    Exception
  */
 public function writeContent(PHPWord $pPHPWord = null)
 {
     // Create XML writer
     $objWriter = null;
     if ($this->getParentWriter()->getUseDiskCaching()) {
         $objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
     } else {
         $objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_MEMORY);
     }
     // XML header
     $objWriter->startDocument('1.0', 'UTF-8');
     // office:document-content
     $objWriter->startElement('office:document-content');
     $objWriter->writeAttribute('xmlns:office', 'urn:oasis:names:tc:opendocument:xmlns:office:1.0');
     $objWriter->writeAttribute('xmlns:style', 'urn:oasis:names:tc:opendocument:xmlns:style:1.0');
     $objWriter->writeAttribute('xmlns:text', 'urn:oasis:names:tc:opendocument:xmlns:text:1.0');
     $objWriter->writeAttribute('xmlns:table', 'urn:oasis:names:tc:opendocument:xmlns:table:1.0');
     $objWriter->writeAttribute('xmlns:draw', 'urn:oasis:names:tc:opendocument:xmlns:drawing:1.0');
     $objWriter->writeAttribute('xmlns:fo', 'urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0');
     $objWriter->writeAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink');
     $objWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/');
     $objWriter->writeAttribute('xmlns:meta', 'urn:oasis:names:tc:opendocument:xmlns:meta:1.0');
     $objWriter->writeAttribute('xmlns:number', 'urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0');
     $objWriter->writeAttribute('xmlns:svg', 'urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0');
     $objWriter->writeAttribute('xmlns:chart', 'urn:oasis:names:tc:opendocument:xmlns:chart:1.0');
     $objWriter->writeAttribute('xmlns:dr3d', 'urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0');
     $objWriter->writeAttribute('xmlns:math', 'http://www.w3.org/1998/Math/MathML');
     $objWriter->writeAttribute('xmlns:form', 'urn:oasis:names:tc:opendocument:xmlns:form:1.0');
     $objWriter->writeAttribute('xmlns:script', 'urn:oasis:names:tc:opendocument:xmlns:script:1.0');
     $objWriter->writeAttribute('xmlns:ooo', 'http://openoffice.org/2004/office');
     $objWriter->writeAttribute('xmlns:ooow', 'http://openoffice.org/2004/writer');
     $objWriter->writeAttribute('xmlns:oooc', 'http://openoffice.org/2004/calc');
     $objWriter->writeAttribute('xmlns:dom', 'http://www.w3.org/2001/xml-events');
     $objWriter->writeAttribute('xmlns:xforms', 'http://www.w3.org/2002/xforms');
     $objWriter->writeAttribute('xmlns:xsd', 'http://www.w3.org/2001/XMLSchema');
     $objWriter->writeAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
     $objWriter->writeAttribute('xmlns:rpt', 'http://openoffice.org/2005/report');
     $objWriter->writeAttribute('xmlns:of', 'urn:oasis:names:tc:opendocument:xmlns:of:1.2');
     $objWriter->writeAttribute('xmlns:xhtml', 'http://www.w3.org/1999/xhtml');
     $objWriter->writeAttribute('xmlns:grddl', 'http://www.w3.org/2003/g/data-view#');
     $objWriter->writeAttribute('xmlns:tableooo', 'http://openoffice.org/2009/table');
     $objWriter->writeAttribute('xmlns:field', 'urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0');
     $objWriter->writeAttribute('xmlns:formx', 'urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0');
     $objWriter->writeAttribute('xmlns:css3t', 'http://www.w3.org/TR/css3-text/');
     $objWriter->writeAttribute('office:version', '1.2');
     // We firstly search all fonts used
     $_sections = $pPHPWord->getSections();
     $countSections = count($_sections);
     if ($countSections > 0) {
         $pSection = 0;
         $numPStyles = 0;
         $numFStyles = 0;
         foreach ($_sections as $section) {
             $pSection++;
             $_elements = $section->getElements();
             foreach ($_elements as $element) {
                 if ($element instanceof PHPWord_Section_Text) {
                     $fStyle = $element->getFontStyle();
                     $pStyle = $element->getParagraphStyle();
                     if ($fStyle instanceof PHPWord_Style_Font) {
                         $numFStyles++;
                         $arrStyle = array('color' => $fStyle->getColor(), 'name' => $fStyle->getName());
                         $pPHPWord->addFontStyle('T' . $numFStyles, $arrStyle);
                         $element->setFontStyle('T' . $numFStyles);
                     } elseif ($pStyle instanceof PHPWord_Style_Paragraph) {
                         $numPStyles++;
                         $pPHPWord->addParagraphStyle('P' . $numPStyles, array());
                         $element->setParagraph('P' . $numPStyles);
                     }
                 }
             }
         }
     }
     // office:font-face-decls
     $objWriter->startElement('office:font-face-decls');
     $arrFonts = array();
     $styles = PHPWord_Style::getStyles();
     $numFonts = 0;
     if (count($styles) > 0) {
         foreach ($styles as $styleName => $style) {
             // PHPWord_Style_Font
             if ($style instanceof PHPWord_Style_Font) {
                 $numFonts++;
                 $name = $style->getName();
                 if (!in_array($name, $arrFonts)) {
                     $arrFonts[] = $name;
                     // style:font-face
                     $objWriter->startElement('style:font-face');
                     $objWriter->writeAttribute('style:name', $name);
                     $objWriter->writeAttribute('svg:font-family', $name);
                     $objWriter->endElement();
                 }
             }
//.........这里部分代码省略.........
开发者ID:heruprambadi,项目名称:sim_penyuratan,代码行数:101,代码来源:Content.php


注:本文中的PHPWord::getSections方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。