我有一个HTML字符串,我想以与HTML中相同的格式和样式在word文档中打印.我正在使用PHPWord
当我给我的HTML字符串说:
$htmlval ="<h6><div style="text-align: center;"><b style=\\"font-size: x-large;\\">OFFER LETTER</b></div><font size=\\"3\\"><div style="text-align: center;"><span style=\\"font-size: medium;\\">(This goes as an email copy)</span></div>";
这是带有break和div的HTML标签.
至:
$section->addText($htmlval);
Run Code Online (Sandbox Code Playgroud)
它打印所有HTML标签,但我希望内容具有HTML中指定的格式.
Tom*_*ski 15
它的可能性有限,但仅适用于基本的html标签.
<p>,<h1>,<h2>,<h3>,<h4>,<h5>,<h6>,<strong>,
<em>,<sup>,<sub>,<table>,<tr>,<td>,<ul>,<ol>,<li>
Run Code Online (Sandbox Code Playgroud)
它在更复杂的情况下也不能很好地工作(例如表格中的rowspan/colspan)
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->addSection();
\PhpOffice\PhpWord\Shared\Html::addHtml($section, $html);
Run Code Online (Sandbox Code Playgroud)
请检查以下示例:PHPWord github
| 归档时间: |
|
| 查看次数: |
15409 次 |
| 最近记录: |