无法导出包含html段落标签的phpword库的docx
我正在使用此 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不能仅将HTML格式的文本写入DOCX字段。
You can't just write the HTML formatted text into a DOCX field.