使用PHP和PHPWord将HTML代码转换为doc [英] Convert HTML code to doc using PHP and PHPWord

查看:1794
本文介绍了使用PHP和PHPWord将HTML代码转换为doc的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用PHPWord加载docx模板并替换 {test} 之类的标签。这是工作得很好。

I am using PHPWord to load a docx template and replace tags like {test}. This is working perfectly fine.

但我想用html代码替换一个值。直接将其替换为模板是不可能的。据我所知,现在有一种方法可以使用PHPWord。

But I want to replace a value with html code. Directly replacing it into the template is not possible. There is now way to do this using PHPWord, as far as I know.

我查看了htmltodocx。但是它接近它也行不通,是否有可能改变像< p>测试< b>测试< / b>< br>测试< / p> 转换成正常的文档标记?我只需要基本的代码,没有风格。但Linebreaks必须工作。

I looked at htmltodocx. But it seams it will not work either, is it posible to transform a peace of code like <p>Test<b>test</b><br>test</p> to a working doc markup? I only need the basic code, no styleing. but Linebreaks have to work.

推荐答案

这里是链接到github。它工作正常 Html-Docx-js

Here is the link to the github. It is working fine Html-Docx-js.

这个演示也可以在这里

其他选项是链接

 $toOpenXML = HTMLtoOpenXML::getInstance()->fromHTML("<p>te<b>s</b>t</p>");
    $templateProcessor->setValue('test', $toOpenXML);

这篇关于使用PHP和PHPWord将HTML代码转换为doc的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆