【发布时间】:2020-12-08 08:13:18
【问题描述】:
我正在使用 PHPWord 来解析 HTML 内容并从中生成一个 .docx 文件。 我想为所有标签添加样式,使它们看起来像网页中的 HTML 链接,例如:带下划线的蓝色。 现在他们在生成的 .docx 文件中看起来是黑色的,没有下划线文本。
这是现在的代码:
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->addSection();
$content = 'one two <a href="https://google.com/">three</a> four five';
\PhpOffice\PhpWord\Shared\Html::addHtml($section, $content, false, false);
$phpWord->save('myfile.docx', 'Word2007', true);
我知道我可以像这样使用内联 CSS(并且它可以工作):
$content = 'one two <a href="https://google.com/" style="color: blue; text-decoration: underline;">three</a> four five';
但我真的不想对每个标签都这样做。 我希望能够为任何传入的标签设置样式,就像在段落或标题中一样设置样式,例如“addTitleStyle”。
另外,我不能使用“addLink”,我目前必须使用“addHtml”
【问题讨论】: