PhpOffice\PhpWord loadTemplate not rendering Word as it should

谁说我不能喝 提交于 2019-11-30 20:03:52

问题


I have problem with rendering HTML tags when load template. I use HTMLtoOpenXML to render it, but in the end it is just plain code. I use this:

$workDescription = $entity->getWorkDescription();
$workDescription = \HTMLtoOpenXML::getInstance()->fromHTML(str_replace("<br />","<br>", stripslashes($workDescription)));
$workDescription = $this->replaceSpecialChar($workDescription);

$phpWord = new \PhpOffice\PhpWord\PhpWord();
$document = $phpWord->loadTemplate($templatePath);
$document->setValue('Description', $workDescription);
$document->saveAs($file);

And PhpWord load document, and set description from variable, but output is something like this in rendered document:

<w:p>
    <w:pPr>
        <w:pStyle w:val='OurStyle2'/>
    </w:pPr>
    <w:r>
        <w:t xml:space='preserve'>
            Test of CK Editor tags to transform them to word,
        </w:t>
    </w:r>
</w:p>
<w:p>
    <w:pPr>
        <w:pStyle w:val='OurStyle2'/>
    </w:pPr>
    <w:r>
        <w:t xml:space='preserve'>
            With a paragraph
        </w:t>
    </w:r>
</w:p>

If I do not use HTMLtoOpenXML I get:

<p>Test of CK Editor tags to transform them to word,</p>
<p>With a paragraph</p>

So this looks like I'm missing something. Any help?

来源:https://stackoverflow.com/questions/27312321/phpoffice-phpword-loadtemplate-not-rendering-word-as-it-should

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!