Convert HTML code to doc using PHP and PHPWord

Alexander Fuchs picture Alexander Fuchs · May 6, 2015 · Viewed 15.2k times · Source

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

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.

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.

Answer

Varun Naharia picture Varun Naharia · May 6, 2015

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

And it is the demo also available here.

Other option is this Link.

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