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

sf_*_*anb 4 html php tinymce ms-word

我已经成功地.docx使用https://github.com/djpate/docxgen生成了一个文档,但是一旦我尝试包含TinyMCE文本,我就再也无法打开文档了.(无效的char).

有没有办法在将HTML文本提供给docxgen之前将其转换为避免此类错误?

rel*_*pse 6

最后,我决定用这个答案来创建一个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);
Run Code Online (Sandbox Code Playgroud)


sf_*_*anb 4

我决定使用该库的专业版本http://www.phpdocx.com/因为它简化了整个过程。我希望它能满足我的需求。

  • 该软件是私有的,您必须付费才能使用几乎所有有用的功能,因此这不是一个好的解决方案。 (4认同)