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


PHP PhpWord\Settings类代码示例

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


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

示例1: mergeDOCX

 function mergeDOCX($source_file, $merged_file)
 {
     // Important: we get the merge data first, because the phpWord
     // autoloader included below stuffs up the Jethro autoloader
     // and causes errors.
     $data = array_values($this->getMergeData());
     // NB THIS FILE HAS BEEN CHANGED!
     require_once 'include/phpword/src/PhpWord/Autoloader.php';
     \PhpOffice\PhpWord\Autoloader::register();
     \PhpOffice\PhpWord\Settings::setTempDir(dirname($source_file));
     $templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor($source_file);
     if (!$templateProcessor->cloneBlock('MERGEBLOCK', count($data))) {
         $vars = $templateProcessor->getVariables();
         if (empty($vars)) {
             trigger_error("You don't seem to have included any \${keywords} in your file; cannot merge");
             return;
         }
         $templateProcessor->cloneRow(reset($vars), count($data));
     }
     foreach ($data as $num => $row) {
         foreach ($row as $k => $v) {
             $templateProcessor->setValue(strtoupper($k) . '#' . ($num + 1), $this->xmlEntities($v));
         }
     }
     $templateProcessor->saveAs($merged_file);
 }
开发者ID:vanoudt,项目名称:jethro-pmm,代码行数:26,代码来源:call_odf_merge.class.php

示例2: testZipArchive

 /**
  * Test all methods
  *
  * @param string $zipClass
  * @covers ::<public>
  */
 public function testZipArchive($zipClass = 'ZipArchive')
 {
     // Preparation
     $existingFile = __DIR__ . '/../_files/documents/sheet.xls';
     $zipFile = __DIR__ . '/../_files/documents/ziptest.zip';
     $destination1 = __DIR__ . '/../_files/documents/extract1';
     $destination2 = __DIR__ . '/../_files/documents/extract2';
     @mkdir($destination1);
     @mkdir($destination2);
     Settings::setZipClass($zipClass);
     $object = new ZipArchive();
     $object->open($zipFile, ZipArchive::CREATE);
     $object->addFile($existingFile, 'xls/new.xls');
     $object->addFromString('content/string.txt', 'Test');
     $object->close();
     $object->open($zipFile);
     // Run tests
     $this->assertEquals(0, $object->locateName('xls/new.xls'));
     $this->assertFalse($object->locateName('blablabla'));
     $this->assertEquals('Test', $object->getFromName('content/string.txt'));
     $this->assertEquals('Test', $object->getFromName('/content/string.txt'));
     $this->assertFalse($object->getNameIndex(-1));
     $this->assertEquals('content/string.txt', $object->getNameIndex(1));
     $this->assertFalse($object->extractTo('blablabla'));
     $this->assertTrue($object->extractTo($destination1));
     $this->assertTrue($object->extractTo($destination2, 'xls/new.xls'));
     $this->assertFalse($object->extractTo($destination2, 'blablabla'));
     // Cleanup
     $this->deleteDir($destination1);
     $this->deleteDir($destination2);
     @unlink($zipFile);
 }
开发者ID:HaiLeader,项目名称:quizz,代码行数:38,代码来源:ZipArchiveTest.php

示例3: __construct

 /**
  * @since 0.12.0 Throws CreateTemporaryFileException and CopyFileException instead of Exception.
  *
  * @param string $documentTemplate The fully qualified template filename.
  *
  * @throws \PhpOffice\PhpWord\Exception\CreateTemporaryFileException
  * @throws \PhpOffice\PhpWord\Exception\CopyFileException
  */
 public function __construct($documentTemplate)
 {
     // Temporary document filename initialization
     $this->tempDocumentFilename = tempnam(Settings::getTempDir(), 'PhpWord');
     if (false === $this->tempDocumentFilename) {
         throw new CreateTemporaryFileException();
     }
     // Template file cloning
     if (false === copy($documentTemplate, $this->tempDocumentFilename)) {
         throw new CopyFileException($documentTemplate, $this->tempDocumentFilename);
     }
     // Temporary document content extraction
     $this->zipClass = new ZipArchive();
     $this->zipClass->open($this->tempDocumentFilename);
     $index = 1;
     while (false !== $this->zipClass->locateName($this->getHeaderName($index))) {
         $this->tempDocumentHeaders[$index] = $this->fixBrokenMacros($this->zipClass->getFromName($this->getHeaderName($index)));
         $index++;
     }
     $index = 1;
     while (false !== $this->zipClass->locateName($this->getFooterName($index))) {
         $this->tempDocumentFooters[$index] = $this->fixBrokenMacros($this->zipClass->getFromName($this->getFooterName($index)));
         $index++;
     }
     $this->tempDocumentMainPart = $this->fixBrokenMacros($this->zipClass->getFromName('word/document.xml'));
     $this->temporaryWordRelDocumentPart = $this->zipClass->getFromName('word/_rels/document.xml.rels');
     $this->temporaryContentType = $this->zipClass->getFromName('[Content_Types].xml');
     // clean the temporary document
     $this->cleanTemporaryDocument();
 }
开发者ID:ptournem,项目名称:phpword,代码行数:38,代码来源:TemplateProcessor.php

示例4: __construct

 /**
  * Create new XMLWriter
  *
  * @param int $tempLocation Temporary storage location
  * @param string $tempFolder Temporary storage folder
  */
 public function __construct($tempLocation = self::STORAGE_MEMORY, $tempFolder = './')
 {
     // Create internal XMLWriter
     $this->xmlWriter = new \XMLWriter();
     // Open temporary storage
     if ($tempLocation == self::STORAGE_MEMORY) {
         $this->xmlWriter->openMemory();
     } else {
         // Create temporary filename
         $this->tempFile = @tempnam($tempFolder, 'xml');
         // Open storage
         if ($this->xmlWriter->openUri($this->tempFile) === false) {
             // Fallback to memory...
             $this->xmlWriter->openMemory();
         }
     }
     // Set xml Compatibility
     $compatibility = Settings::getCompatibility();
     if ($compatibility) {
         $this->xmlWriter->setIndent(false);
         $this->xmlWriter->setIndentString('');
     } else {
         $this->xmlWriter->setIndent(true);
         $this->xmlWriter->setIndentString('  ');
     }
 }
开发者ID:kaantunc,项目名称:MYK-BOR,代码行数:32,代码来源:XMLWriter.php

示例5: writeStyles

 /**
  * Get styles
  *
  * @return string
  */
 private function writeStyles()
 {
     $css = '<style>' . PHP_EOL;
     // Default styles
     $defaultStyles = array('*' => array('font-family' => Settings::getDefaultFontName(), 'font-size' => Settings::getDefaultFontSize() . 'pt'), 'a.NoteRef' => array('text-decoration' => 'none'), 'hr' => array('height' => '1px', 'padding' => '0', 'margin' => '1em 0', 'border' => '0', 'border-top' => '1px solid #CCC'));
     foreach ($defaultStyles as $selector => $style) {
         $styleWriter = new GenericStyleWriter($style);
         $css .= $selector . ' {' . $styleWriter->write() . '}' . PHP_EOL;
     }
     // Custom styles
     $customStyles = Style::getStyles();
     if (is_array($customStyles)) {
         foreach ($customStyles as $name => $style) {
             if ($style instanceof Font) {
                 $styleWriter = new FontStyleWriter($style);
                 if ($style->getStyleType() == 'title') {
                     $name = str_replace('Heading_', 'h', $name);
                 } else {
                     $name = '.' . $name;
                 }
                 $css .= "{$name} {" . $styleWriter->write() . '}' . PHP_EOL;
             } elseif ($style instanceof Paragraph) {
                 $styleWriter = new ParagraphStyleWriter($style);
                 $name = '.' . $name;
                 $css .= "{$name} {" . $styleWriter->write() . '}' . PHP_EOL;
             }
         }
     }
     $css .= '</style>' . PHP_EOL;
     return $css;
 }
开发者ID:samogot,项目名称:rura-convertors,代码行数:36,代码来源:Head.php

示例6: PhpWord

 function __construct($testResultsHandler)
 {
     Autoloader::register();
     Settings::loadConfig();
     $this->testResultsHandler = $testResultsHandler;
     $this->phpWord = new PhpWord();
 }
开发者ID:KDRS-TEST,项目名称:noark5-validator,代码行数:7,代码来源:ReportBuilder.php

示例7: __construct

 /**
  * @since 0.12.0 Throws CreateTemporaryFileException and CopyFileException instead of Exception.
  *
  * @param string $documentTemplate The fully qualified template filename.
  * @throws \PhpOffice\PhpWord\Exception\CreateTemporaryFileException
  * @throws \PhpOffice\PhpWord\Exception\CopyFileException
  */
 public function __construct($documentTemplate)
 {
     // Temporary document filename initialization
     $this->temporaryDocumentFilename = tempnam(Settings::getTempDir(), 'PhpWord');
     if (false === $this->temporaryDocumentFilename) {
         throw new CreateTemporaryFileException();
     }
     // Template file cloning
     if (false === copy($documentTemplate, $this->temporaryDocumentFilename)) {
         throw new CopyFileException($documentTemplate, $this->temporaryDocumentFilename);
     }
     // Temporary document content extraction
     $this->zipClass = new ZipArchive();
     $this->zipClass->open($this->temporaryDocumentFilename);
     $index = 1;
     while ($this->zipClass->locateName($this->getHeaderName($index)) !== false) {
         $this->temporaryDocumentHeaders[$index] = $this->zipClass->getFromName($this->getHeaderName($index));
         $index++;
     }
     $index = 1;
     while ($this->zipClass->locateName($this->getFooterName($index)) !== false) {
         $this->temporaryDocumentFooters[$index] = $this->zipClass->getFromName($this->getFooterName($index));
         $index++;
     }
     $this->temporaryDocumentMainPart = $this->zipClass->getFromName('word/document.xml');
 }
开发者ID:cakpep,项目名称:spk-tht,代码行数:33,代码来源:TemplateProcessor.php

示例8: __construct

 /**
  * Create new XMLWriter
  *
  * @param int $tempLocation Temporary storage location
  * @param string $tempFolder Temporary storage folder
  */
 public function __construct($tempLocation = self::STORAGE_MEMORY, $tempFolder = './')
 {
     // Create internal XMLWriter
     $this->xmlWriter = new \XMLWriter();
     // Open temporary storage
     if ($tempLocation == self::STORAGE_MEMORY) {
         $this->xmlWriter->openMemory();
     } else {
         // Create temporary filename
         $this->tempFile = @tempnam($tempFolder, 'xml');
         // Fallback to memory when temporary file cannot be used
         // @codeCoverageIgnoreStart
         // Can't find any test case. Uncomment when found.
         if ($this->xmlWriter->openUri($this->tempFile) === false) {
             $this->xmlWriter->openMemory();
         }
         // @codeCoverageIgnoreEnd
     }
     // Set xml Compatibility
     $compatibility = Settings::hasCompatibility();
     if ($compatibility) {
         $this->xmlWriter->setIndent(false);
         $this->xmlWriter->setIndentString('');
     } else {
         $this->xmlWriter->setIndent(true);
         $this->xmlWriter->setIndentString('  ');
     }
 }
开发者ID:FabianoFaria,项目名称:ULA_front,代码行数:34,代码来源:XMLWriter.php

示例9: write

 /**
  * Write link element.
  *
  * @return void
  */
 public function write()
 {
     $xmlWriter = $this->getXmlWriter();
     $element = $this->getElement();
     if (!$element instanceof \PhpOffice\PhpWord\Element\Link) {
         return;
     }
     $rId = $element->getRelationId() + ($element->isInSection() ? 6 : 0);
     $this->startElementP();
     $xmlWriter->startElement('w:hyperlink');
     if ($element->isInternal()) {
         $xmlWriter->writeAttribute('w:anchor', $element->getSource());
     } else {
         $xmlWriter->writeAttribute('r:id', 'rId' . $rId);
     }
     $xmlWriter->writeAttribute('w:history', '1');
     $xmlWriter->startElement('w:r');
     $this->writeFontStyle();
     $xmlWriter->startElement('w:t');
     $xmlWriter->writeAttribute('xml:space', 'preserve');
     if (Settings::isOutputEscapingEnabled()) {
         $xmlWriter->text($element->getText());
     } else {
         $xmlWriter->writeRaw($element->getText());
     }
     $xmlWriter->endElement();
     // w:t
     $xmlWriter->endElement();
     // w:r
     $xmlWriter->endElement();
     // w:hyperlink
     $this->endElementP();
     // w:p
 }
开发者ID:matiasvillanueva,项目名称:laravel5-CRUD-LOGIN,代码行数:39,代码来源:Link.php

示例10: __construct

 /**
  * Create a new Template Object
  *
  * @param string $strFilename
  * @throws \PhpOffice\PhpWord\Exception\Exception
  */
 public function __construct($strFilename)
 {
     $this->tempFileName = tempnam(sys_get_temp_dir(), '');
     if ($this->tempFileName === false) {
         throw new Exception('Could not create temporary file with unique name in the default temporary directory.');
     }
     // Copy the source File to the temp File
     if (!copy($strFilename, $this->tempFileName)) {
         throw new Exception("Could not copy the template from {$strFilename} to {$this->tempFileName}.");
     }
     $zipClass = Settings::getZipClass();
     $this->zipClass = new $zipClass();
     $this->zipClass->open($this->tempFileName);
     // Find and load headers and footers
     $index = 1;
     while ($this->zipClass->locateName($this->getHeaderName($index)) !== false) {
         $this->headerXMLs[$index] = $this->zipClass->getFromName($this->getHeaderName($index));
         $index++;
     }
     $index = 1;
     while ($this->zipClass->locateName($this->getFooterName($index)) !== false) {
         $this->footerXMLs[$index] = $this->zipClass->getFromName($this->getFooterName($index));
         $index++;
     }
     $this->documentXML = $this->zipClass->getFromName('word/document.xml');
 }
开发者ID:kaantunc,项目名称:MYK-BOR,代码行数:32,代码来源:Template.php

示例11: write

 /**
  * Write element
  */
 public function write()
 {
     $xmlWriter = $this->getXmlWriter();
     $element = $this->getElement();
     if (!$element instanceof \PhpOffice\PhpWord\Element\Link) {
         return;
     }
     if (!$this->withoutP) {
         $xmlWriter->startElement('text:p');
         // text:p
     }
     $xmlWriter->startElement('text:a');
     $xmlWriter->writeAttribute('xlink:type', 'simple');
     $xmlWriter->writeAttribute('xlink:href', $element->getSource());
     if (Settings::isOutputEscapingEnabled()) {
         $xmlWriter->text($element->getText());
     } else {
         $xmlWriter->writeRaw($element->getText());
     }
     $xmlWriter->endElement();
     // text:a
     if (!$this->withoutP) {
         $xmlWriter->endElement();
         // text:p
     }
 }
开发者ID:matiasvillanueva,项目名称:laravel5-CRUD-LOGIN,代码行数:29,代码来源:Link.php

示例12: write

 /**
  * Write preserve text element.
  *
  * @return void
  */
 public function write()
 {
     $xmlWriter = $this->getXmlWriter();
     $element = $this->getElement();
     if (!$element instanceof \PhpOffice\PhpWord\Element\PreserveText) {
         return;
     }
     $texts = $element->getText();
     if (!is_array($texts)) {
         $texts = array($texts);
     }
     $this->startElementP();
     foreach ($texts as $text) {
         if (substr($text, 0, 1) == '{') {
             $text = substr($text, 1, -1);
             $xmlWriter->startElement('w:r');
             $xmlWriter->startElement('w:fldChar');
             $xmlWriter->writeAttribute('w:fldCharType', 'begin');
             $xmlWriter->endElement();
             $xmlWriter->endElement();
             $xmlWriter->startElement('w:r');
             $this->writeFontStyle();
             $xmlWriter->startElement('w:instrText');
             $xmlWriter->writeAttribute('xml:space', 'preserve');
             if (Settings::isOutputEscapingEnabled()) {
                 $xmlWriter->text($text);
             } else {
                 $xmlWriter->writeRaw($text);
             }
             $xmlWriter->endElement();
             $xmlWriter->endElement();
             $xmlWriter->startElement('w:r');
             $xmlWriter->startElement('w:fldChar');
             $xmlWriter->writeAttribute('w:fldCharType', 'separate');
             $xmlWriter->endElement();
             $xmlWriter->endElement();
             $xmlWriter->startElement('w:r');
             $xmlWriter->startElement('w:fldChar');
             $xmlWriter->writeAttribute('w:fldCharType', 'end');
             $xmlWriter->endElement();
             $xmlWriter->endElement();
         } else {
             $xmlWriter->startElement('w:r');
             $this->writeFontStyle();
             $xmlWriter->startElement('w:t');
             $xmlWriter->writeAttribute('xml:space', 'preserve');
             if (Settings::isOutputEscapingEnabled()) {
                 $xmlWriter->text($this->getText($text));
             } else {
                 $xmlWriter->writeRaw($this->getText($text));
             }
             $xmlWriter->endElement();
             $xmlWriter->endElement();
         }
     }
     $this->endElementP();
     // w:p
 }
开发者ID:matiasvillanueva,项目名称:laravel5-CRUD-LOGIN,代码行数:63,代码来源:PreserveText.php

示例13: clear

 /**
  * Clear document
  */
 public static function clear()
 {
     if (file_exists(self::$file)) {
         unlink(self::$file);
     }
     if (is_dir(Settings::getTempDir() . '/PhpWord_Unit_Test/')) {
         self::deleteDir(Settings::getTempDir() . '/PhpWord_Unit_Test/');
     }
 }
开发者ID:brunodebarros,项目名称:phpword,代码行数:12,代码来源:TestHelperDOCX.php

示例14: _testReadWriteCycleSucks

 public function _testReadWriteCycleSucks()
 {
     PhpWord\Settings::setTempDir(Tinebase_Core::getTempDir());
     $source = str_replace('tests/tine20', 'tine20', __DIR__) . '/templates/addressbook_contact_letter.docx';
     $phpWord = PhpWord\IOFactory::load($source);
     $tempfile = tempnam(Tinebase_Core::getTempDir(), __METHOD__ . '_') . '.docx';
     $writer = $phpWord->save($tempfile);
     `open {$tempfile}`;
 }
开发者ID:ingoratsdorf,项目名称:Tine-2.0-Open-Source-Groupware-and-CRM,代码行数:9,代码来源:DocTest.php

示例15: convertTwip

 /**
  * Convert twip value
  *
  * @param int|float $value
  * @param int|float $default
  * @return int|float
  */
 protected function convertTwip($value, $default = 0)
 {
     $unit = Settings::getMeasurementUnit();
     if ($unit == Settings::UNIT_TWIP || $value == $default) {
         return $value;
     } else {
         return $value * $unit;
     }
 }
开发者ID:kaantunc,项目名称:MYK-BOR,代码行数:16,代码来源:AbstractStyle.php


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