无法导出包含html段落标签的phpword库的docx

发布于 2025-02-13 16:15:32 字数 689 浏览 0 评论 0原文

我正在使用此 library

代码示例:

<?php

use \PhpOffice\PhpWord\PhpWord;

$phpWord = new PhpWord();
$section = $phpWord->addSection();
$section->addText('test');
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
$objWriter->save('Appdividend.docx');
return response()->download(public_path('Appdividend.docx'));

它可以正常工作,它可以正常运行,并带有“ test”文本,test test docx文件,但是,当替换此行时:

$ section-&gt; addtext('test');与此

$ section-&gt; addText('&lt; p&gt; test&lt;/p&gt;'); docx文档是空的。

I'm using this library

Code example:

<?php

use \PhpOffice\PhpWord\PhpWord;

$phpWord = new PhpWord();
$section = $phpWord->addSection();
$section->addText('test');
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
$objWriter->save('Appdividend.docx');
return response()->download(public_path('Appdividend.docx'));

It works fine and returns docx file with "test" text, but when replace this row :

$section->addText('test'); with this one

$section->addText('<p>test</p>'); the docx document is empty.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风筝有风,海豚有海 2025-02-20 16:15:32

您不能仅将HTML格式的文本写入DOCX字段。

You can't just write the HTML formatted text into a DOCX field.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文