当前位置: 首页>>代码示例>>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;未经允许,请勿转载。