用phpword中的setValue使单词大胆
在PHPWord中使用TemplateProcessor时如何使替换的单词加粗并加下划线?发现的解决方案非常古老(2016)。
我尝试创建我的函数来编辑 xml 文档,但完成的文件崩溃了。
我的代码:
$path = public_path()."/example/dogovor.docx";
$document = new TemplateProcessor($path);
$document->setValue('student-name', 'Alex');
$document->saveAs(public_path("documents/test.docx"));
尝试过这个功能:
private function makeWordBold($str, $hex=null, $style='b'): string
{
$cor = $hex ? "<w:color w:val='".$hex."'/>" : "";
$before="/w:t/w:r<w:r><w:rPr>".$cor."<w:".$style."/>/w:rPr<w:t xml:space='preserve'>";
$after='/w:t/w:r<w:r><w:t>';
return $before.$str.$after;
}
How to make the replaced word bold and underline when using TemplateProcessor in PHPWord? Found solutions are very old (2016).
I tried to create my function, to edit xml document, but done file is crashing.
My code:
$path = public_path()."/example/dogovor.docx";
$document = new TemplateProcessor($path);
$document->setValue('student-name', 'Alex');
$document->saveAs(public_path("documents/test.docx"));
Tried this function:
private function makeWordBold($str, $hex=null, $style='b'): string
{
$cor = $hex ? "<w:color w:val='".$hex."'/>" : "";
$before="/w:t/w:r<w:r><w:rPr>".$cor."<w:".$style."/>/w:rPr<w:t xml:space='preserve'>";
$after='/w:t/w:r<w:r><w:t>';
return $before.$str.$after;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我尝试编写自己的代码,因此它可以处理一个句子中存在多个
标记或也有
标记的情况。我的想法是制作自己独特的标签来替换 HTML 标签。
I tried to make my own code, so it can handle if there are more than one
<strong>
tag or there is<em>
tag too in one sentence. The idea is I make my own unique tags to replace the HTML tags.