使用PhpWord生成ms word文档

时间:2018-01-30 07:04:47

标签: php ms-word ms-office phpword

我将使用PhpWord生成一些文档,我有一些草稿文档,我动态设置void Grid::placeBoat(int iX1, int iY1, int iX2, int iY2) const

const

然后我读了这个文件,用户可以下载

Grid

当我尝试通过 MsOffice 打开它时,我收到此消息: pretty much the same

点击 确定 时: enter image description here

并且在接受了这个之后我终于看到了我的文件。生成可读文档需要什么?

1 个答案:

答案 0 :(得分:0)

我刚刚在阅读之前将ob_clean()添加到我的代码中,一切正常。

  

此函数丢弃输出缓冲区的内容。

     

此函数不会像ob_end_clean()那样破坏输出缓冲区   确实

所以我确保不需要的输出不会进入生成的文档。

$templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor($draftUrl);
$templateProcessor->setValue("client_name", $clientName);

$filename = '30.docx';
$templateProcessor->saveAs($filename);

header('Content-Type: application/octet-stream');
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
header("Content-Disposition: attachment; filename='$filename'");
ob_clean();
readfile($filename);
相关问题