我正在尝试使用 PHPWord 加载 .docx 文件,在其中设置一个值,然后保存该文件。问题是保存的文件显示为空白 Word 文档,大小为 7kb。我放入的文档很大并且有多个页面。显然它加载不正确。我的代码如下:
$PHPWord = new \PhpOffice\PhpWord\PhpWord();
$document = $PHPWord->loadTemplate('Resources/documents/test.docx');
$document->setValue('theDate', '2014-07-25');
$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($PHPWord, 'Word2007');
$xmlWriter->save("php://output");
我尝试过使用多个不同类型的 test.docx 文件,但输出文件始终为空。
最佳答案
我能够通过 Progi1984 链接的内容解决这个问题,调用 $document->saveAs() 然后读取文件以下载它。谢谢:)
关于php - 使用 PHPWord 加载 .docx,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24999805/