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


PHP Settings::setCompatibility方法代码示例

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


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

示例1: testSetGetCompatibility

 /**
  * Test set/get compatibity option
  */
 public function testSetGetCompatibility()
 {
     $this->assertTrue(Settings::getCompatibility());
     $this->assertTrue(Settings::setCompatibility(false));
     $this->assertFalse(Settings::getCompatibility());
     $this->assertFalse(Settings::setCompatibility('Non boolean'));
 }
开发者ID:kaantunc,项目名称:MYK-BOR,代码行数:10,代码来源:SettingsTest.php

示例2: convertImpl


//.........这里部分代码省略.........
        } else {
            $credit = "<h2>Реквизиты переводчиков</h2>";
            if ($this->command) {
                $credit .= "<p>Перевод команды {$this->command}</p>";
            }
            foreach ($this->workers as $activity => $workers) {
                $credit .= '<p>' . $activity . ': <b>' . implode('</b>, <b>', $workers) . "</b></p>\n";
            }
            $credit .= '<p>Версия от ' . date('d.m.Y', $this->touched) . '</p>
						  <p><b>Любое коммерческое использование данного текста или его фрагментов запрещено</b></p>';
        }
        if ($this->height == 0) {
            $text = preg_replace('/(<p[^>]*>)?<img[^>]*>(<\\/p>)?/u', '', $text);
        } else {
            for ($i = 1; $i < count($this->covers); ++$i) {
                $image = $this->images[$this->covers[$i]];
                $text = "<img src=\"" . $image['thumbnail'] . "\" width=\"" . $image['convert_width'] . "\" height=\"" . $image['convert_height'] . "\" />" . $text;
            }
            $text = preg_replace_callback('/(<a[^>]*>)?<img[^>]*data-resource-id="(-?\\d*)"[^>]*>(<\\/a>)?/u', function ($match) use(&$images) {
                if ($match[2] < 0) {
                    return '';
                }
                $image = $this->images[$match[2]];
                /* Width and height are unimportant. Actual resizing is done not in this class. We must save aspect ratio though. */
                return "<img src=\"" . $image['thumbnail'] . "\" width=\"" . $image['convert_width'] . "\" height=\"" . $image['convert_height'] . "\" />";
            }, $text);
        }
        $footnotes = array();
        $footnotes_temp = explode(',;,', $this->footnotes);
        for ($i = 0; $i < sizeof($footnotes_temp); $i++) {
            if (is_numeric($footnotes_temp[$i])) {
                $footnotes[$footnotes_temp[$i]] = $footnotes_temp[$i + 1];
                $i++;
            }
        }
        $text = trim($text);
        $epubText = "<html>\n\t<body>\n\t\t{$descr['coverpage']}\n\t\t{$descr['author']}\n\t\t{$descr['sequence']}\n\t    {$descr['annotation']}\n\t\t{$credit}\n\t\t{$text}\n\t</body>\n\t</html>";
        $epubText = preg_replace_callback('@(<span[^>]*><a href="#cite_note-(\\d*)"[^>]*>.{0,15}</span>)@', function ($match) use(&$footnotes) {
            $footnote = $footnotes[$match[2]];
            $footnote = preg_replace('@</p>\\s*<p[^>]*>@', '<br/>', $footnote);
            if ($footnote) {
                return '<footnote>' . $footnote . '</footnote>';
            } else {
                return $match[1];
            }
        }, $epubText);
        //preg_replace('@cite_note-(\d*)@',"<footnote></footnote>", $epubText);
        //echo '<xmp>'.$epubText;
        //echo $footnotes[137603266];
        //exit;
        //echo '<xmp>'.$epubText;
        //exit;
        $epubText = preg_replace('@section@', "div", $epubText);
        /* Delete extra <br/> tag before images */
        $epubText = preg_replace('@<div>(.){0,20}<br\\/>(.){0,20}<img src@', '<div><img src', $epubText);
        /* Eliminate caret return before <h1> (Each div starts with caret return in h2d_htmlconverter.php) */
        $epubText = preg_replace('@\\s*<div>(.{0,40})(<h1>.*?<\\/h1>)@', '\\1\\2<div>', $epubText);
        /* NGNL Specific names */
        //$text=str_replace('<span style="position: relative; text-indent: 0;"><span style="display: inline-block; font-style: normal">&#12302;&#12288;&#12288;&#12288;&#12303;</span><span style="position: absolute; font-size: .7em; top: -11px; left: 50%"><span style="position: relative; left: -50%;">','&#12302;<sup>',$text);
        //$text=str_replace('</span></span></span>','</sup>&#12303;',$text);
        // Styles of elements in which footnote is nested should not count. Thus close them
        $epubText = preg_replace('@pb@', "br", $epubText);
        //echo '<xmp>'.$epubText;
        //exit;
        //PHPWord doesn't support tags nested in link element. Unnest images from them
        $epubText = preg_replace('@<a[^>]*>(<img[^>]*>)<\\/a>@', "\\1", $epubText);
        // Delete extra page breaks related to images.
        $epubText = preg_replace('@<div[^>]*>(.){0,20}(<img[^>]*>)(.){0,20}<\\/div>@', "\\1\\2\\3", $epubText);
        $epubText = preg_replace('@<p[^>]*>(.){0,20}(<img[^>]*>)(.){0,20}<\\/p>@', "\\1\\2\\3", $epubText);
        /* Swap h2 and img tags if img follows h2. (It gave a bad look in docx). */
        $epubText = preg_replace('@(<h2>.{0,100}<\\/h2>)(<img[^>]*>)@', '\\2\\1', $epubText);
        /* After swap we often needs to further lift img tag in previous <div> or <p> tag */
        $epubText = preg_replace('@<\\/div>(<img[^>]*>)<h2@', '\\1</div><h2', $epubText);
        $epubText = preg_replace('@<\\/p>(<img[^>]*>)<h2@', '\\1</p><h2', $epubText);
        //echo '<xmp>'.$epubText;
        //exit;
        $phpword_object = new \PhpOffice\PhpWord\PhpWord();
        \PhpOffice\PhpWord\Settings::setCompatibility(false);
        $html_dom = new \simple_html_dom();
        $html_dom->load($epubText);
        $html_dom_array = $html_dom->find('html', 0)->children();
        $paths = htmltodocx_paths();
        $initial_state = ['phpword_object' => &$phpword_object, 'base_root' => $paths['base_root'], 'base_path' => $paths['base_path'], 'current_style' => ['size' => '11'], 'parents' => [0 => 'body'], 'list_depth' => 0, 'context' => 'section', 'pseudo_list' => true, 'pseudo_list_indicator_font_name' => 'Wingdings', 'pseudo_list_indicator_font_size' => '7', 'pseudo_list_indicator_character' => 'l ', 'table_allowed' => true, 'treat_div_as_paragraph' => true, 'structure_headings' => true, 'structure_document' => true, 'style_sheet' => htmltodocx_styles_example()];
        htmltodocx_insert_html($phpword_object, $html_dom_array[0]->nodes, $initial_state);
        //var_dump($html_dom_array[0]->nodes);
        //		exit;
        $html_dom->clear();
        unset($html_dom);
        $h2d_file_uri = tempnam(sys_get_temp_dir(), 'htd');
        /*if ($h2d_file_uri === false) {
              var_dump(sys_get_temp_dir());
          }*/
        $objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpword_object, 'Word2007');
        $objWriter->save($h2d_file_uri);
        $bin = file_get_contents($h2d_file_uri);
        unlink($h2d_file_uri);
        //echo 'sdfjnsdlkvjn';
        //exit;
        return $bin;
    }
开发者ID:samogot,项目名称:rura-convertors,代码行数:101,代码来源:DocxConverter.php

示例3: date

<?php

include_once 'Sample_Header.php';
// New Word Document
echo date('H:i:s'), ' Create new PhpWord object', EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
\PhpOffice\PhpWord\Settings::setCompatibility(false);
// New portrait section
$section = $phpWord->addSection();
// Add style definitions
$phpWord->addParagraphStyle('pStyle', array('spacing' => 100));
$phpWord->addFontStyle('BoldText', array('bold' => true));
$phpWord->addFontStyle('ColoredText', array('color' => 'FF8080'));
$phpWord->addLinkStyle('NLink', array('color' => '0000FF', 'underline' => \PhpOffice\PhpWord\Style\Font::UNDERLINE_SINGLE));
// Add text elements
$textrun = $section->addTextRun('pStyle');
$textrun->addText(htmlspecialchars('This is some lead text in a paragraph with a following footnote. ', ENT_COMPAT, 'UTF-8'), 'pStyle');
$footnote = $textrun->addFootnote();
$footnote->addText(htmlspecialchars('Just like a textrun, a footnote can contain native texts. ', ENT_COMPAT, 'UTF-8'));
$footnote->addText(htmlspecialchars('No break is placed after adding an element. ', ENT_COMPAT, 'UTF-8'), 'BoldText');
$footnote->addText(htmlspecialchars('All elements are placed inside a paragraph. ', ENT_COMPAT, 'UTF-8'), 'ColoredText');
$footnote->addTextBreak();
$footnote->addText(htmlspecialchars('But you can insert a manual text break like above, ', ENT_COMPAT, 'UTF-8'));
$footnote->addText(htmlspecialchars('links like ', ENT_COMPAT, 'UTF-8'));
$footnote->addLink('https://github.com/PHPOffice/PHPWord', htmlspecialchars('PHPWord on GitHub', ENT_COMPAT, 'UTF-8'), 'NLink');
$footnote->addText(htmlspecialchars(', image like ', ENT_COMPAT, 'UTF-8'));
$footnote->addImage('resources/_earth.jpg', array('width' => 18, 'height' => 18));
$footnote->addText(htmlspecialchars(', or object like ', ENT_COMPAT, 'UTF-8'));
$footnote->addObject('resources/_sheet.xls');
$footnote->addText(htmlspecialchars('But you can only put footnote in section, not in header or footer.', ENT_COMPAT, 'UTF-8'));
$section->addText(htmlspecialchars('You can also create the footnote directly from the section making it wrap in a paragraph ' . 'like the footnote below this paragraph. But is is best used from within a textrun.', ENT_COMPAT, 'UTF-8'));
开发者ID:doit05,项目名称:relProject,代码行数:31,代码来源:Sample_06_Footnote.php

示例4: testCallException

 /**
  * Test method exception
  *
  * @expectedException \BadMethodCallException
  * @expectedExceptionMessage Method 'foo' does not exists.
  */
 public function testCallException()
 {
     Settings::setCompatibility(false);
     $object = new XMLWriter();
     $object->foo();
 }
开发者ID:doit05,项目名称:relProject,代码行数:12,代码来源:XMLWriterTest.php

示例5: testSetGetCompatibility

 /**
  * Test set/get compatibity option
  */
 public function testSetGetCompatibility()
 {
     $this->assertTrue(Settings::hasCompatibility());
     $this->assertTrue(Settings::setCompatibility(false));
     $this->assertFalse(Settings::hasCompatibility());
 }
开发者ID:brunodebarros,项目名称:phpword,代码行数:9,代码来源:SettingsTest.php


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