OpenTbs convert html tags to MS Word tags

后端 未结 3 2017
忘了有多久
忘了有多久 2021-01-07 13:55

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

I have a template.docx and am able to replace fields with content but if th

3条回答
  •  孤街浪徒
    2021-01-07 14:04

    Since you have a conversion function for HTML to DOCX, then you can implement it in OpenTBS using a custom PHP function and parameter "onformat".

    The following function only convert line breaks:

    function f_html2docx($FieldName, &$CurrVal) {
      $CurrVal= str_replace('
    ', '', $CurrVal); }

    Use in the DOCX template :

    [b.thetext;onformat=f_html2docx]
    

    About converting HTML to DOCX :

    Converting a formated text into another formated text is quite often a nightmare. That's why is it wise to store the pure data instead if formated data.

    Converting HTML to DOCX is a real nightmare because the formating is not structured the same way.

    For example, in HTML tags may me nested, like this:

     hello  this is important  to know 
    

    In DOCX it will be presented as crossing, like this :

      
        
        hello
      
    
      
        
        this is important
      
    
      
        
        to know
      
    

    I have no solution for converting tags other than line-breaks for now. Sorry for that. And I think it would be quite difficult to code one.

提交回复
热议问题