當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。