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

发布于 2025-01-07 14:03:41 字数 232 浏览 0 评论 0原文

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

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

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. (non valid char).

Is there a way to convert the HTML text before giving it to docxgen to avoid such error?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

爱,才寂寞 2025-01-14 14:03:41

最后,我用这个答案解决了创建一个文档(只需输出 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);

Finally, I settled with this answer to create a doc (simply output html and Word will recognize it):

    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);
猫瑾少女 2025-01-14 14:03:41

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

I've decided to go with the pro version of the library http://www.phpdocx.com/ as it simplifies the whole process. I hope it'll fill my needs.

毁梦 2025-01-14 14:03:41

另一个解决方案是使用最近发布的 http://htmltodocx.codeplex.com/

然而,我尝试了一下,它弄乱了我的发票(假设我使用了不应该使用的桌子)

吉姆

Another solution is using http://htmltodocx.codeplex.com/ which just recently came out.

I, however, tried it and it messed up my invoice (granted I used tables where I shouldn't have)

Jim

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文