當前位置: 首頁>>代碼示例>>PHP>>正文


PHP PhpWord\PhpWord類代碼示例

本文整理匯總了PHP中PhpOffice\PhpWord\PhpWord的典型用法代碼示例。如果您正苦於以下問題:PHP PhpWord類的具體用法?PHP PhpWord怎麽用?PHP PhpWord使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了PhpWord類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: read

 /**
  * Read styles.xml.
  *
  * @param \PhpOffice\PhpWord\PhpWord $phpWord
  * @return void
  */
 public function read(PhpWord $phpWord)
 {
     $xmlReader = new XMLReader();
     $xmlReader->getDomFromZip($this->docFile, $this->xmlFile);
     $nodes = $xmlReader->getElements('w:style');
     if ($nodes->length > 0) {
         foreach ($nodes as $node) {
             $type = $xmlReader->getAttribute('w:type', $node);
             $name = $xmlReader->getAttribute('w:styleId', $node);
             if (is_null($name)) {
                 $name = $xmlReader->getAttribute('w:val', $node, 'w:name');
             }
             preg_match('/Heading(\\d)/', $name, $headingMatches);
             // $default = ($xmlReader->getAttribute('w:default', $node) == 1);
             switch ($type) {
                 case 'paragraph':
                     $paragraphStyle = $this->readParagraphStyle($xmlReader, $node);
                     $fontStyle = $this->readFontStyle($xmlReader, $node);
                     if (!empty($headingMatches)) {
                         $phpWord->addTitleStyle($headingMatches[1], $fontStyle, $paragraphStyle);
                     } else {
                         if (empty($fontStyle)) {
                             if (is_array($paragraphStyle)) {
                                 $phpWord->addParagraphStyle($name, $paragraphStyle);
                             }
                         } else {
                             $phpWord->addFontStyle($name, $fontStyle, $paragraphStyle);
                         }
                     }
                     break;
                 case 'character':
                     $fontStyle = $this->readFontStyle($xmlReader, $node);
                     if (!empty($fontStyle)) {
                         $phpWord->addFontStyle($name, $fontStyle);
                     }
                     break;
                 case 'table':
                     $tStyle = $this->readTableStyle($xmlReader, $node);
                     if (!empty($tStyle)) {
                         $phpWord->addTableStyle($name, $tStyle);
                     }
                     break;
             }
         }
     }
 }
開發者ID:doit05,項目名稱:relProject,代碼行數:52,代碼來源:Styles.php

示例2: 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

示例3: read

 /**
  * Read meta.xml.
  *
  * @param \PhpOffice\PhpWord\PhpWord $phpWord
  * @return void
  * @todo Process property type
  */
 public function read(PhpWord $phpWord)
 {
     $xmlReader = new XMLReader();
     $xmlReader->getDomFromZip($this->docFile, $this->xmlFile);
     $docProps = $phpWord->getDocInfo();
     $metaNode = $xmlReader->getElement('office:meta');
     // Standard properties
     $properties = array('title' => 'dc:title', 'subject' => 'dc:subject', 'description' => 'dc:description', 'keywords' => 'meta:keyword', 'creator' => 'meta:initial-creator', 'lastModifiedBy' => 'dc:creator');
     foreach ($properties as $property => $path) {
         $method = "set{$property}";
         $propertyNode = $xmlReader->getElement($path, $metaNode);
         if ($propertyNode !== null && method_exists($docProps, $method)) {
             $docProps->{$method}($propertyNode->nodeValue);
         }
     }
     // Custom properties
     $propertyNodes = $xmlReader->getElements('meta:user-defined', $metaNode);
     foreach ($propertyNodes as $propertyNode) {
         $property = $xmlReader->getAttribute('meta:name', $propertyNode);
         // Set category, company, and manager property
         if (in_array($property, array('Category', 'Company', 'Manager'))) {
             $method = "set{$property}";
             $docProps->{$method}($propertyNode->nodeValue);
             // Set other custom properties
         } else {
             $docProps->setCustomProperty($property, $propertyNode->nodeValue);
         }
     }
 }
開發者ID:matiasvillanueva,項目名稱:laravel5-CRUD-LOGIN,代碼行數:36,代碼來源:Meta.php

示例4: 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

示例5: testWriteStyles

 /**
  * Test write styles
  */
 public function testWriteStyles()
 {
     $phpWord = new PhpWord();
     $pStyle = array('align' => 'both');
     $pBase = array('basedOn' => 'Normal');
     $pNew = array('basedOn' => 'Base Style', 'next' => 'Normal');
     $rStyle = array('size' => 20);
     $tStyle = array('bgColor' => 'FF0000', 'cellMarginTop' => 120, 'cellMarginBottom' => 120, 'cellMarginLeft' => 120, 'cellMarginRight' => 120, 'borderTopSize' => 120, 'borderBottomSize' => 120, 'borderLeftSize' => 120, 'borderRightSize' => 120, 'borderInsideHSize' => 120, 'borderInsideVSize' => 120);
     $phpWord->setDefaultParagraphStyle($pStyle);
     $phpWord->addParagraphStyle('Base Style', $pBase);
     $phpWord->addParagraphStyle('New Style', $pNew);
     $phpWord->addFontStyle('New Style', $rStyle, $pStyle);
     $phpWord->addTableStyle('Table Style', $tStyle, $tStyle);
     $phpWord->addTitleStyle(1, $rStyle, $pStyle);
     $doc = TestHelperDOCX::getDocument($phpWord);
     $file = 'word/styles.xml';
     // Normal style generated?
     $path = '/w:styles/w:style[@w:styleId="Normal"]/w:name';
     $element = $doc->getElement($path, $file);
     $this->assertEquals('Normal', $element->getAttribute('w:val'));
     // Parent style referenced?
     $path = '/w:styles/w:style[@w:styleId="New Style"]/w:basedOn';
     $element = $doc->getElement($path, $file);
     $this->assertEquals('Base Style', $element->getAttribute('w:val'));
     // Next paragraph style correct?
     $path = '/w:styles/w:style[@w:styleId="New Style"]/w:next';
     $element = $doc->getElement($path, $file);
     $this->assertEquals('Normal', $element->getAttribute('w:val'));
 }
開發者ID:kaantunc,項目名稱:MYK-BOR,代碼行數:32,代碼來源:StylesTest.php

示例6: testWriteNumbering

 /**
  * Write footnotes
  */
 public function testWriteNumbering()
 {
     $xmlFile = 'word/numbering.xml';
     $phpWord = new PhpWord();
     $phpWord->addNumberingStyle('numStyle', array('type' => 'multilevel', 'levels' => array(array('start' => 1, 'format' => 'decimal', 'restart' => 1, 'suffix' => 'space', 'text' => '%1.', 'alignment' => Jc::START, 'left' => 360, 'hanging' => 360, 'tabPos' => 360, 'font' => 'Arial', 'hint' => 'default'))));
     $doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
     $this->assertTrue($doc->elementExists('/w:numbering/w:abstractNum', $xmlFile));
 }
開發者ID:HaiLeader,項目名稱:quizz,代碼行數:11,代碼來源:NumberingTest.php

示例7: 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

示例8: 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

示例9: testCompatibility

 /**
  * Test compatibility
  */
 public function testCompatibility()
 {
     $phpWord = new PhpWord();
     $phpWord->getCompatibility()->setOoxmlVersion(15);
     $doc = TestHelperDOCX::getDocument($phpWord);
     $file = 'word/settings.xml';
     $path = '/w:settings/w:compat/w:compatSetting';
     $this->assertTrue($doc->elementExists($path, $file));
 }
開發者ID:matiasvillanueva,項目名稱:laravel5-CRUD-LOGIN,代碼行數:12,代碼來源:SettingsTest.php

示例10: 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

示例11: testTabsStyle

 /**
  * Test if the tabs has been created properly
  */
 public function testTabsStyle()
 {
     $phpWord = new PhpWord();
     $phpWord->addParagraphStyle('tabbed', array('tabs' => array(new Tab('left', 1440, 'dot'))));
     $doc = TestHelperDOCX::getDocument($phpWord);
     $file = 'word/styles.xml';
     $path = '/w:styles/w:style[@w:styleId="tabbed"]/w:pPr/w:tabs/w:tab[1]';
     $element = $doc->getElement($path, $file);
     $this->assertEquals('left', $element->getAttribute('w:val'));
     $this->assertEquals(1440, $element->getAttribute('w:pos'));
     $this->assertEquals('dot', $element->getAttribute('w:leader'));
 }
開發者ID:kaantunc,項目名稱:MYK-BOR,代碼行數:15,代碼來源:TabsTest.php

示例12: 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

示例13: read

 /**
  * Read numbering.xml.
  *
  * @param \PhpOffice\PhpWord\PhpWord $phpWord
  * @return void
  */
 public function read(PhpWord $phpWord)
 {
     $abstracts = array();
     $numberings = array();
     $xmlReader = new XMLReader();
     $xmlReader->getDomFromZip($this->docFile, $this->xmlFile);
     // Abstract numbering definition
     $nodes = $xmlReader->getElements('w:abstractNum');
     if ($nodes->length > 0) {
         foreach ($nodes as $node) {
             $abstractId = $xmlReader->getAttribute('w:abstractNumId', $node);
             $abstracts[$abstractId] = array('levels' => array());
             $abstract =& $abstracts[$abstractId];
             $subnodes = $xmlReader->getElements('*', $node);
             foreach ($subnodes as $subnode) {
                 switch ($subnode->nodeName) {
                     case 'w:multiLevelType':
                         $abstract['type'] = $xmlReader->getAttribute('w:val', $subnode);
                         break;
                     case 'w:lvl':
                         $levelId = $xmlReader->getAttribute('w:ilvl', $subnode);
                         $abstract['levels'][$levelId] = $this->readLevel($xmlReader, $subnode, $levelId);
                         break;
                 }
             }
         }
     }
     // Numbering instance definition
     $nodes = $xmlReader->getElements('w:num');
     if ($nodes->length > 0) {
         foreach ($nodes as $node) {
             $numId = $xmlReader->getAttribute('w:numId', $node);
             $abstractId = $xmlReader->getAttribute('w:val', $node, 'w:abstractNumId');
             $numberings[$numId] = $abstracts[$abstractId];
             $numberings[$numId]['numId'] = $numId;
             $subnodes = $xmlReader->getElements('w:lvlOverride/w:lvl', $node);
             foreach ($subnodes as $subnode) {
                 $levelId = $xmlReader->getAttribute('w:ilvl', $subnode);
                 $overrides = $this->readLevel($xmlReader, $subnode, $levelId);
                 foreach ($overrides as $key => $value) {
                     $numberings[$numId]['levels'][$levelId][$key] = $value;
                 }
             }
         }
     }
     // Push to Style collection
     foreach ($numberings as $numId => $numbering) {
         $phpWord->addNumberingStyle("PHPWordList{$numId}", $numbering);
     }
 }
開發者ID:brunodebarros,項目名稱:phpword,代碼行數:56,代碼來源:Numbering.php

示例14: 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

示例15: 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


注:本文中的PhpOffice\PhpWord\PhpWord類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。