I use phpoffice/phpword to work with document templating, the example can be found here: https://github.com/PHPOffice/PHPWord/blob/master/samples/old/Template.php.
The problem is I need to insert formatted text which is html code generated from wysiwyg editor. I can't do:
$document->setValue('Value1', '<span>Sun</span>');
Document generation will be error, I guess because the library can't parse html along with the OpenXML. What I need to do is, probably, convert the html first to OpenXML, I tried it but always get:

I don't know. Any idea or suggestion how to deal with this ? will be greatly apreciated. Thanks.
You can add html to table cell, see example:
$templateProcessor=$PHPWord->loadTemplate('Template.docx');
$value = '<b>TEST</b>';
$wordTable = new \PhpOffice\PhpWord\Element\Table();
$wordTable->addRow();
$cell = $wordTable->addCell();
\PhpOffice\PhpWord\Shared\Html::addHtml($cell,$value);
$templateProcessor->setComplexBlock('SomePlaceholder', $wordTable);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With