How to convert the html tag string to a word document using PHPWord?

自古美人都是妖i 提交于 2019-12-01 03:19:08

In limited way its possible, but just only for basic html tags.

<p>,<h1>,<h2>,<h3>,<h4>,<h5>,<h6>,<strong>,
<em>,<sup>,<sub>,<table>,<tr>,<td>,<ul>,<ol>,<li>

Its also not work well in more complicated cases (for example rowspan/colspan in tables)

$phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->addSection();
\PhpOffice\PhpWord\Shared\Html::addHtml($section, $html);

Please check samples on : PHPWord github

I agree with the answer of @Tomek, but you have more html tags possible.

The full list is here :
https://github.com/PHPOffice/PHPWord/blob/4a530d1d97b064b87d9e2a1cc64cab996246569c/src/PhpWord/Shared/Html.php#L116

Don't try to do complicated thinks with table or style. It just didn't work.

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