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


PHP PhpWord::addSection方法代码示例

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


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

示例1: generateDOC

 public function generateDOC($html)
 {
     $objPHPWord = new PhpWord();
     // Create new PHPWord object
     $section = $objPHPWord->addSection();
     Html::addHtml($section, $html, true);
     $objWriter = IOFactory::createWriter($objPHPWord, 'Word2007');
     ob_start();
     $objWriter->save('php://output');
     $contents = ob_get_clean();
     return $contents;
 }
开发者ID:denisristic,项目名称:word-service-provider,代码行数:12,代码来源:Word.php

示例2: createDocx

 /**
  * Create word file using phpWord library
  *
  * @param array $text
  * @param       $file
  * @return string
  * @throws \PhpOffice\PhpWord\Exception\Exception
  */
 public function createDocx(array $text, $file)
 {
     $file_path = public_path($file);
     $phpWord = new PhpWord();
     foreach ($text as $page) {
         $section = $phpWord->addSection();
         $page = $this->escape($page);
         Html::addHtml($section, $page);
     }
     $objWriter = IOFactory::createWriter($phpWord, 'Word2007');
     $objWriter->save($file_path);
     return $file_path;
 }
开发者ID:sadhakbj,项目名称:resourcecontracts.org,代码行数:21,代码来源:WordGenerator.php

示例3: read

 /**
  * Read document.xml
  *
  * @param \PhpOffice\PhpWord\PhpWord $phpWord
  */
 public function read(PhpWord &$phpWord)
 {
     $xmlReader = new XMLReader();
     $xmlReader->getDomFromZip($this->docFile, $this->xmlFile);
     $nodes = $xmlReader->getElements('w:body/*');
     if ($nodes->length > 0) {
         $section = $phpWord->addSection();
         foreach ($nodes as $node) {
             switch ($node->nodeName) {
                 case 'w:p':
                     // Paragraph
                     // Page break
                     // @todo <w:lastRenderedPageBreak>
                     if ($xmlReader->getAttribute('w:type', $node, 'w:r/w:br') == 'page') {
                         $section->addPageBreak();
                         // PageBreak
                     }
                     // Paragraph
                     $this->readParagraph($xmlReader, $node, $section, 'document');
                     // Section properties
                     if ($xmlReader->elementExists('w:pPr/w:sectPr', $node)) {
                         $settingsNode = $xmlReader->getElement('w:pPr/w:sectPr', $node);
                         if (!is_null($settingsNode)) {
                             $settings = $this->readSectionStyle($xmlReader, $settingsNode);
                             $section->setSettings($settings);
                             if (!is_null($settings)) {
                                 $this->readHeaderFooter($settings, $section);
                             }
                         }
                         $section = $phpWord->addSection();
                     }
                     break;
                 case 'w:tbl':
                     // Table
                     $this->readTable($xmlReader, $node, $section, 'document');
                     break;
                 case 'w:sectPr':
                     // Last section
                     $settings = $this->readSectionStyle($xmlReader, $node);
                     $section->setSettings($settings);
                     if (!is_null($settings)) {
                         $this->readHeaderFooter($settings, $section);
                     }
                     break;
             }
         }
     }
 }
开发者ID:kaantunc,项目名称:MYK-BOR,代码行数:53,代码来源:Document.php

示例4: read

 /**
  * Read content.xml
  *
  * @param \PhpOffice\PhpWord\PhpWord $phpWord
  */
 public function read(PhpWord &$phpWord)
 {
     $xmlReader = new XMLReader();
     $xmlReader->getDomFromZip($this->docFile, $this->xmlFile);
     $nodes = $xmlReader->getElements('office:body/office:text/*');
     if ($nodes->length > 0) {
         $section = $phpWord->addSection();
         foreach ($nodes as $node) {
             // $styleName = $xmlReader->getAttribute('text:style-name', $node);
             switch ($node->nodeName) {
                 case 'text:h':
                     // Heading
                     $depth = $xmlReader->getAttribute('text:outline-level', $node);
                     $section->addTitle($node->nodeValue, $depth);
                     break;
                 case 'text:p':
                     // Paragraph
                     $section->addText($node->nodeValue);
                     break;
                 case 'text:list':
                     // List
                     $listItems = $xmlReader->getElements('text:list-item/text:p', $node);
                     foreach ($listItems as $listItem) {
                         // $listStyleName = $xmlReader->getAttribute('text:style-name', $listItem);
                         $section->addListItem($listItem->nodeValue);
                     }
                     break;
             }
         }
     }
 }
开发者ID:kaantunc,项目名称:MYK-BOR,代码行数:36,代码来源:Content.php

示例5: testSavePhpOutput

 /**
  * Save php output
  *
  * @todo   Haven't got any method to test this
  */
 public function testSavePhpOutput()
 {
     $phpWord = new PhpWord();
     $section = $phpWord->addSection();
     $section->addText('Test');
     $writer = new ODText($phpWord);
     $writer->save('php://output');
 }
开发者ID:kaantunc,项目名称:MYK-BOR,代码行数:13,代码来源:ODTextTest.php

示例6: load

 /**
  * Loads PhpWord from file
  *
  * @param string $docFile
  *
  * @throws \Exception
  *
  * @return \PhpOffice\PhpWord\PhpWord
  */
 public function load($docFile)
 {
     $phpWord = new PhpWord();
     if ($this->canRead($docFile)) {
         $section = $phpWord->addSection();
         HTMLParser::addHtml($section, file_get_contents($docFile), true);
     } else {
         throw new \Exception("Cannot read {$docFile}.");
     }
     return $phpWord;
 }
开发者ID:matiasvillanueva,项目名称:laravel5-CRUD-LOGIN,代码行数:20,代码来源:HTML.php

示例7: getDocFileStr

 /**
  * 生成简历文件字符串
  * @param $sp_id 快照主键
  * @param string $type 类型 doc/doc_no_contact(隐藏了联系方式)
  */
 public function getDocFileStr($id, $type = 'doc_no_contact')
 {
     $sp_model = new ResumeSnapshot();
     $sp_info = $sp_model->getResumeSnapshotInfoById($id);
     //根据简历快照生成word
     $phpWord = new PhpWord();
     // New portrait section
     $section = $phpWord->addSection();
     // Add header for all other pages //todo logo图片需传到线上
     $subsequent = $section->addHeader();
     $subsequent->addText(htmlspecialchars('51CTO高招-中高端IT人才的招聘平台'));
     $subsequent->addImage('http://job.51cto.com/pic/logo_s.jpg', array('width' => 80, 'height' => 80, 'align' => 'right'));
     ////        $section = $phpWord->addSection();
     //        $html = '<h1>Adding element via HTML</h1>';
     //        $html .= '<p>Some well formed HTML snippet needs to be used</p>';
     //        $html .= '<p>With for example <strong>some<sup>1</sup> <em>inline</em> formatting</strong><sub>1</sub></p>';
     //        $html .= '<p>Unordered (bulleted) list:</p>';
     //        $html .= '<ul><li>Item 1</li><li>Item 2</li><ul><li>Item 2.1</li><li>Item 2.1</li></ul></ul>';
     //        $html .= '<p>Ordered (numbered) list:</p>';
     //        $html .= '<ol><li>Item 1</li><li>Item 2</li></ol>';
     //
     //        \PhpOffice\PhpWord\Shared\Html::addHtml($section, $html);
     $section = $phpWord->addSection();
     $header = array('size' => 16, 'bold' => true);
     //1.Use EastAisa FontStyle
     $section->addText(htmlspecialchars('邵燕'), array('name' => '微软雅黑', 'size' => '二号', 'color' => '1B2232'));
     $section->addText(htmlspecialchars('邵燕'), array('name' => '微软雅黑', 'size' => '二号', 'color' => '1B2232'));
     $objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
     $rand = time() . rand(10000, 99999);
     $file = WEB_ROOT . "/runtime/{$rand}.docx";
     //临时文件
     $file = WEB_ROOT . "/runtime/test.docx";
     //临时文件
     $objWriter->save($file, 'Word2007', true);
     //        $file_str = file_get_contents($file);
     //        unlink($file);//删除文件
     //
     //        return $file_str;
 }
开发者ID:breezelife0,项目名称:mycode,代码行数:44,代码来源:Sample_Header.php

示例8: testConstruct

 /**
  * Test construct
  */
 public function testConstruct()
 {
     $file = __DIR__ . '/../../_files/mpdf.pdf';
     $phpWord = new PhpWord();
     $section = $phpWord->addSection();
     $section->addText(htmlspecialchars('Test 1', ENT_COMPAT, 'UTF-8'));
     $rendererName = Settings::PDF_RENDERER_MPDF;
     $rendererLibraryPath = realpath(PHPWORD_TESTS_BASE_DIR . '/../vendor/mpdf/mpdf');
     Settings::setPdfRenderer($rendererName, $rendererLibraryPath);
     $writer = new PDF($phpWord);
     $writer->save($file);
     $this->assertTrue(file_exists($file));
     unlink($file);
 }
开发者ID:doit05,项目名称:relProject,代码行数:17,代码来源:MPDFTest.php

示例9: testConstruct

 /**
  * Test construct
  */
 public function testConstruct()
 {
     $file = __DIR__ . "/../../_files/tcpdf.pdf";
     $phpWord = new PhpWord();
     $section = $phpWord->addSection();
     $section->addText('Test 1');
     $rendererName = Settings::PDF_RENDERER_TCPDF;
     $rendererLibraryPath = realpath(PHPWORD_TESTS_BASE_DIR . '/../vendor/tecnick.com/tcpdf');
     Settings::setPdfRenderer($rendererName, $rendererLibraryPath);
     $writer = new PDF($phpWord);
     $writer->save($file);
     $this->assertTrue(file_exists($file));
     unlink($file);
 }
开发者ID:productioncompilers,项目名称:PHPWord,代码行数:17,代码来源:TCPDFTest.php

示例10: testConstruct

 /**
  * Test construct
  */
 public function testConstruct()
 {
     define('DOMPDF_ENABLE_AUTOLOAD', false);
     $file = __DIR__ . "/../../_files/temp.pdf";
     $phpWord = new PhpWord();
     $section = $phpWord->addSection();
     $section->addText('Test 1');
     $rendererName = Settings::PDF_RENDERER_DOMPDF;
     $rendererLibraryPath = realpath(PHPWORD_TESTS_BASE_DIR . '/../vendor/dompdf/dompdf');
     Settings::setPdfRenderer($rendererName, $rendererLibraryPath);
     $writer = new PDF($phpWord);
     $writer->save($file);
     $this->assertTrue(file_exists($file));
     unlink($file);
 }
开发者ID:kaantunc,项目名称:MYK-BOR,代码行数:18,代码来源:DomPDFTest.php

示例11: testWriteFootnotes

 /**
  * Write footnotes
  */
 public function testWriteFootnotes()
 {
     $phpWord = new PhpWord();
     $phpWord->addParagraphStyle('pStyle', array('align' => 'left'));
     $section = $phpWord->addSection();
     $section->addText(htmlspecialchars('Text', ENT_COMPAT, 'UTF-8'));
     $footnote1 = $section->addFootnote('pStyle');
     $footnote1->addText(htmlspecialchars('Footnote', ENT_COMPAT, 'UTF-8'));
     $footnote1->addTextBreak();
     $footnote1->addLink('https://github.com/PHPOffice/PHPWord');
     $footnote2 = $section->addEndnote(array('align' => 'left'));
     $footnote2->addText(htmlspecialchars('Endnote', ENT_COMPAT, 'UTF-8'));
     $doc = TestHelperDOCX::getDocument($phpWord);
     $this->assertTrue($doc->elementExists('/w:document/w:body/w:p/w:r/w:footnoteReference'));
     $this->assertTrue($doc->elementExists('/w:document/w:body/w:p/w:r/w:endnoteReference'));
 }
开发者ID:var23rav,项目名称:toword_by_PhpWord,代码行数:19,代码来源:FootnotesTest.php

示例12: testWriteFootnotes

 /**
  * Write footnotes
  */
 public function testWriteFootnotes()
 {
     $phpWord = new PhpWord();
     $phpWord->addParagraphStyle('pStyle', array('align' => 'left'));
     $section = $phpWord->addSection();
     $section->addText('Text');
     $footnote1 = $section->addFootnote('pStyle');
     $footnote1->addText('Footnote');
     $footnote1->addTextBreak();
     $footnote1->addLink('http://google.com');
     $footnote2 = $section->addEndnote(array('align' => 'left'));
     $footnote2->addText('Endnote');
     $doc = TestHelperDOCX::getDocument($phpWord);
     $this->assertTrue($doc->elementExists("/w:document/w:body/w:p/w:r/w:footnoteReference"));
     $this->assertTrue($doc->elementExists("/w:document/w:body/w:p/w:r/w:endnoteReference"));
 }
开发者ID:productioncompilers,项目名称:PHPWord,代码行数:19,代码来源:FootnotesTest.php

示例13: readWPNode

 /**
  * Read w:p node
  *
  * @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader
  * @param \DOMElement $node
  * @param \PhpOffice\PhpWord\Element\Section $section
  *
  * @todo <w:lastRenderedPageBreak>
  */
 private function readWPNode(XMLReader $xmlReader, \DOMElement $node, Section &$section)
 {
     // Page break
     if ($xmlReader->getAttribute('w:type', $node, 'w:r/w:br') == 'page') {
         $section->addPageBreak();
         // PageBreak
     }
     // Paragraph
     $this->readParagraph($xmlReader, $node, $section);
     // Section properties
     if ($xmlReader->elementExists('w:pPr/w:sectPr', $node)) {
         $sectPrNode = $xmlReader->getElement('w:pPr/w:sectPr', $node);
         if ($sectPrNode !== null) {
             $this->readWSectPrNode($xmlReader, $sectPrNode, $section);
         }
         $section = $this->phpWord->addSection();
     }
 }
开发者ID:FabianoFaria,项目名称:ULA_front,代码行数:27,代码来源:Document.php

示例14: testWriteContent

 /**
  * Test write content
  */
 public function testWriteContent()
 {
     $imageSrc = __DIR__ . '/../../../_files/images/PhpWord.png';
     $objectSrc = __DIR__ . '/../../../_files/documents/sheet.xls';
     $expected = 'Expected';
     $phpWord = new PhpWord();
     $docProps = $phpWord->getDocInfo();
     $docProps->setCustomProperty('Company', 'PHPWord');
     $phpWord->setDefaultFontName('Verdana');
     $phpWord->addFontStyle('Font', array('size' => 11));
     $phpWord->addParagraphStyle('Paragraph', array('alignment' => Jc::CENTER));
     $phpWord->addTableStyle('tblStyle', array('width' => 100));
     $section = $phpWord->addSection(array('colsNum' => 2));
     $section->addText(htmlspecialchars($expected, ENT_COMPAT, 'UTF-8'));
     $section->addText(htmlspecialchars('Test font style', ENT_COMPAT, 'UTF-8'), 'Font');
     $section->addText(htmlspecialchars('Test paragraph style', ENT_COMPAT, 'UTF-8'), null, 'Paragraph');
     $section->addLink('https://github.com/PHPOffice/PHPWord', htmlspecialchars('PHPWord on GitHub', ENT_COMPAT, 'UTF-8'));
     $section->addTitle(htmlspecialchars('Test title', ENT_COMPAT, 'UTF-8'), 1);
     $section->addTextBreak();
     $section->addPageBreak();
     $section->addListItem(htmlspecialchars('Test list item', ENT_COMPAT, 'UTF-8'));
     $section->addImage($imageSrc, array('width' => 50));
     $section->addObject($objectSrc);
     $section->addTOC();
     $textrun = $section->addTextRun();
     $textrun->addText(htmlspecialchars('Test text run', ENT_COMPAT, 'UTF-8'));
     $table = $section->addTable(array('width' => 50));
     $cell = $table->addRow()->addCell();
     $cell = $table->addRow()->addCell();
     $cell->addText(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8'));
     $cell->addLink('https://github.com/PHPOffice/PHPWord', htmlspecialchars('PHPWord on GitHub', ENT_COMPAT, 'UTF-8'));
     $cell->addTextBreak();
     $cell->addListItem(htmlspecialchars('Test list item', ENT_COMPAT, 'UTF-8'));
     $cell->addImage($imageSrc);
     $cell->addObject($objectSrc);
     $textrun = $cell->addTextRun();
     $textrun->addText(htmlspecialchars('Test text run', ENT_COMPAT, 'UTF-8'));
     $footer = $section->addFooter();
     $footer->addPreserveText(htmlspecialchars('{PAGE}', ENT_COMPAT, 'UTF-8'));
     $table = $section->addTable('tblStyle')->addRow()->addCell();
     $doc = TestHelperDOCX::getDocument($phpWord, 'ODText');
     $element = '/office:document-content/office:body/office:text/text:section/text:p';
     $this->assertEquals($expected, $doc->getElement($element, 'content.xml')->nodeValue);
 }
开发者ID:doit05,项目名称:relProject,代码行数:47,代码来源:ContentTest.php

示例15: testWriteContent

 /**
  * Test write content
  */
 public function testWriteContent()
 {
     $imageSrc = __DIR__ . "/../../../_files/images/PhpWord.png";
     $objectSrc = __DIR__ . "/../../../_files/documents/sheet.xls";
     $expected = 'Expected';
     $phpWord = new PhpWord();
     $docProps = $phpWord->getDocumentProperties();
     $docProps->setCustomProperty('Company', 'PHPWord');
     $phpWord->setDefaultFontName('Verdana');
     $phpWord->addFontStyle('Font', array('size' => 11));
     $phpWord->addParagraphStyle('Paragraph', array('align' => 'center'));
     $phpWord->addTableStyle('tblStyle', array('width' => 100));
     $section = $phpWord->addSection(array('colsNum' => 2));
     $section->addText($expected);
     $section->addText('Test font style', 'Font');
     $section->addText('Test paragraph style', null, 'Paragraph');
     $section->addLink('http://test.com', 'Test link');
     $section->addTitle('Test title', 1);
     $section->addTextBreak();
     $section->addPageBreak();
     $section->addListItem('Test list item');
     $section->addImage($imageSrc, array('width' => 50));
     $section->addObject($objectSrc);
     $section->addTOC();
     $textrun = $section->addTextRun();
     $textrun->addText('Test text run');
     $table = $section->addTable(array('width' => 50));
     $cell = $table->addRow()->addCell();
     $cell = $table->addRow()->addCell();
     $cell->addText('Test');
     $cell->addLink('http://test.com', 'Test link');
     $cell->addTextBreak();
     $cell->addListItem('Test list item');
     $cell->addImage($imageSrc);
     $cell->addObject($objectSrc);
     $textrun = $cell->addTextRun();
     $textrun->addText('Test text run');
     $footer = $section->addFooter();
     $footer->addPreserveText('{PAGE}');
     $table = $section->addTable('tblStyle')->addRow()->addCell();
     $doc = TestHelperDOCX::getDocument($phpWord, 'ODText');
     $element = "/office:document-content/office:body/office:text/text:section/text:p";
     $this->assertEquals($expected, $doc->getElement($element, 'content.xml')->nodeValue);
 }
开发者ID:hcvcastro,项目名称:pxp,代码行数:47,代码来源:ContentTest.php


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