1. <i id='QeRfY'><tr id='QeRfY'><dt id='QeRfY'><q id='QeRfY'><span id='QeRfY'><b id='QeRfY'><form id='QeRfY'><ins id='QeRfY'></ins><ul id='QeRfY'></ul><sub id='QeRfY'></sub></form><legend id='QeRfY'></legend><bdo id='QeRfY'><pre id='QeRfY'><center id='QeRfY'></center></pre></bdo></b><th id='QeRfY'></th></span></q></dt></tr></i><div id='QeRfY'><tfoot id='QeRfY'></tfoot><dl id='QeRfY'><fieldset id='QeRfY'></fieldset></dl></div>
      1. <legend id='QeRfY'><style id='QeRfY'><dir id='QeRfY'><q id='QeRfY'></q></dir></style></legend>
        <tfoot id='QeRfY'></tfoot>

        • <bdo id='QeRfY'></bdo><ul id='QeRfY'></ul>
      2. <small id='QeRfY'></small><noframes id='QeRfY'>

        OpenTbs 将 html 标签转换为 MS Word 标签

        时间:2023-07-16

          <i id='GpKwT'><tr id='GpKwT'><dt id='GpKwT'><q id='GpKwT'><span id='GpKwT'><b id='GpKwT'><form id='GpKwT'><ins id='GpKwT'></ins><ul id='GpKwT'></ul><sub id='GpKwT'></sub></form><legend id='GpKwT'></legend><bdo id='GpKwT'><pre id='GpKwT'><center id='GpKwT'></center></pre></bdo></b><th id='GpKwT'></th></span></q></dt></tr></i><div id='GpKwT'><tfoot id='GpKwT'></tfoot><dl id='GpKwT'><fieldset id='GpKwT'></fieldset></dl></div>
          • <small id='GpKwT'></small><noframes id='GpKwT'>

          • <tfoot id='GpKwT'></tfoot>
              • <bdo id='GpKwT'></bdo><ul id='GpKwT'></ul>
                  <tbody id='GpKwT'></tbody>
                • <legend id='GpKwT'><style id='GpKwT'><dir id='GpKwT'><q id='GpKwT'></q></dir></style></legend>
                  本文介绍了OpenTbs 将 html 标签转换为 MS Word 标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在使用 OpenTbs,http://www.tinybutstrong.com/plugins/opentbs/tbs_plugin_opentbs.html.

                  I am using OpenTbs, http://www.tinybutstrong.com/plugins/opentbs/tbs_plugin_opentbs.html.

                  我有一个 template.docx 并且能够用内容替换字段,但如果内容有 html 代码,它会显示在模板创建的文档中.

                  I have a template.docx and am able to replace fields with content but if the content has html code it is displayed in the document created by the template.

                  First list <br /> Second Line
                  

                  我曾尝试使用:

                  $TBS->LoadTemplate('document.docx', OPENTBS_ALREADY_XML); 
                  

                  认为这将允许我用 ms office 标签替换我的 html 标签,但它只是在文档中显示了 MS Office 标签:

                  Thinking this would allow me to replace my html tags with ms office tags, but it just showed the MS Office tags in the document instead:

                  First Line<w:br/> Second Line
                  

                  如何将 HTML 标记转换为等效的 MS Office XML.

                  How do i convert the HTML tags into the MS Office XML equivalent.

                  推荐答案

                  感谢 Skrol 对我所有 openTBS 问题的投入,只是注意到你是它的创建者,它是一个很棒的类,并且你上面说的在之后是正确的通过学习 MS Word 格式的一天我有一个脑波,我现在能够生成您在上面指定的格式,并且可以使用粗斜体和下划线,这是我所需要的,我希望这为您提供了改进的基础

                  Thanks Skrol for your input on all my openTBS issues, just noticed that you are the creator of it, its a great class and what you said above was true after a day of plowing through learning the MS Word Format i had a brain wave and I am now able to produce the format that you specified above and can have bold italic and underline which is all i require, I hope this gives you a foundation to improve upon.

                  我基本上注意到,在您放置的示例中,您只需要一个样式数组,当您找到一个结束标记时,您就可以从样式数组中删除它.每次您找到一个标签时,您都需要关闭 <w:r> 并创建一个新标签,我已经对其进行了测试,并且效果很好.

                  I basically noticed that in the example you put you just need an array of the styles which when you find a closing tag you remove from the style array. Each time you find a tag you need to close the <w:r> and create a new one, I have tested it and it works wonderfully.

                  class printClass {
                      private static $currentStyles = array();    
                  
                      public function __construct() {}
                  
                      public function format($string) {
                              if($string !=""){
                              return preg_replace_callback("#<b>|<u>|<i>|</b>|</u>|</i>#",
                                                          'printClass::replaceTags',
                                                          $string);
                          }else{
                              return false;
                          }
                      }
                  
                  
                      private static function applyStyles() {
                  
                          if(count(self::$currentStyles) > 0 ) {
                  
                              foreach(self::$currentStyles as $value) {
                  
                                  if($value == "b") {
                                      $styles .= "<w:b/>";
                                  }   
                  
                                  if($value == "u") {
                                      $styles .= "<w:u w:val="single"/>";
                                  }   
                  
                                  if($value == "i") {
                                      $styles .= "<w:i/>";
                                  }
                              }
                  
                              return "<w:rPr>" . $styles . "</w:rPr>";
                          }else{
                              return false;
                          }
                      }
                  
                  
                  
                      private static function replaceTags($matches) {
                  
                          if($matches[0] == "<b>") {
                              array_push(self::$currentStyles, "b");
                          }   
                  
                          if($matches[0] == "<u>") {
                              array_push(self::$currentStyles, "u");
                          }   
                  
                          if($matches[0] == "<i>") {
                              array_push(self::$currentStyles, "i");
                          }
                  
                          if($matches[0] == "</b>") {
                              self::$currentStyles = array_diff(self::$currentStyles, array("b"));
                          }   
                  
                          if($matches[0] == "</u>") {
                              self::$currentStyles = array_diff(self::$currentStyles, array("u"));
                          }   
                  
                          if($matches[0] == "</i>") {
                              self::$currentStyles = array_diff(self::$currentStyles, array("i"));
                          }
                  
                          return "</w:t></w:r><w:r>" . self::applyStyles() . "<w:t xml:space="preserve">";
                      }
                  }
                  

                  这篇关于OpenTbs 将 html 标签转换为 MS Word 标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:使用 PHP 从 MS Word 文档中提取图像的最简单方法? 下一篇:PHP:发送WORD文档文件下载

                  相关文章

                  <legend id='0snoo'><style id='0snoo'><dir id='0snoo'><q id='0snoo'></q></dir></style></legend>

                    <small id='0snoo'></small><noframes id='0snoo'>

                    <tfoot id='0snoo'></tfoot>
                      <bdo id='0snoo'></bdo><ul id='0snoo'></ul>
                    1. <i id='0snoo'><tr id='0snoo'><dt id='0snoo'><q id='0snoo'><span id='0snoo'><b id='0snoo'><form id='0snoo'><ins id='0snoo'></ins><ul id='0snoo'></ul><sub id='0snoo'></sub></form><legend id='0snoo'></legend><bdo id='0snoo'><pre id='0snoo'><center id='0snoo'></center></pre></bdo></b><th id='0snoo'></th></span></q></dt></tr></i><div id='0snoo'><tfoot id='0snoo'></tfoot><dl id='0snoo'><fieldset id='0snoo'></fieldset></dl></div>