简体   繁体   English

将HTML(tinyMCE)转换为WORD(.docx)

[英]Convert HTML (tinyMCE) to WORD (.docx)

I've been successfully able to generate a .docx document with https://github.com/djpate/docxgen but as soon as i try to include TinyMCE text, i no longer can open the document. 我已经成功地使用https://github.com/djpate/docxgen生成.docx文档,但是一旦我尝试包含TinyMCE文本,我就再也无法打开文档了。 (non valid char). (无效的char)。

Is there a way to convert the HTML text before giving it to docxgen to avoid such error? 有没有办法在将HTML文本提供给docxgen之前将其转换为避免此类错误?

Finally, I settled with this answer to create a doc (simply output html and Word will recognize it): 最后,我决定用这个答案来创建一个doc(简单地输出html,Word会识别它):

    header( 'Content-Type: application/msword' ); 
    header("Content-disposition: attachment; filename=" .date("Y-m-d").".doc");  
    /*
    header("Content-type: application/vnd.ms-word");
    header("Content-disposition: attachment; filename=" .date("Y-m-d").".rtf");
    */
    $html = preg_replace('%/[^\\s]+\\.(jpg|jpeg|png|gif)%i', 'http://www.akubocrm.com\\0', $html);

    print "<html xmlns:v=\"urn:schemas-microsoft-com:vml\"";
    print "xmlns:o=\"urn:schemas-microsoft-com:office:office\"";
    print "xmlns:w=\"urn:schemas-microsoft-com:office:word\"";
    print "xmlns=\"http://www.w3.org/TR/REC-html40\">";
    print "<xml>
     <w:WordDocument>
      <w:View>Print</w:View>
      <w:DoNotHyphenateCaps/>
      <w:PunctuationKerning/>
      <w:DrawingGridHorizontalSpacing>9.35 pt</w:DrawingGridHorizontalSpacing>
      <w:DrawingGridVerticalSpacing>9.35 pt</w:DrawingGridVerticalSpacing>
     </w:WordDocument>
    </xml>
    ";

    die($html);

I've decided to go with the pro version of the library http://www.phpdocx.com/ as it simplifies the whole process. 我决定使用库http://www.phpdocx.com/的专业版,因为它简化了整个过程。 I hope it'll fill my needs. 我希望它能满足我的需求。

Another solution is using http://htmltodocx.codeplex.com/ which just recently came out. 另一个解决方案是使用最近刚出来的http://htmltodocx.codeplex.com/

I, however, tried it and it messed up my invoice (granted I used tables where I shouldn't have) 然而,我尝试了它,它弄乱了我的发票(授予我使用的桌子,我不应该)

Jim 吉姆

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM