【发布时间】:2016-04-25 21:57:58
【问题描述】:
我在 laravel 应用程序中集成了 PHP office。当我在我的 xampp localhost 上运行它时它可以工作,但是当我在 IIS 生产服务器上使用它时,我得到“很抱歉,我们无法打开 text.docx,因为我们发现它的内容有问题。文件已损坏并且无法打开。”我可以单击另外两个警告我“不可读内容”的错误弹出窗口,然后打开文件。当我最终打开文件时,它看起来很好。 IIS 服务器使用 php 版本 5.6.14、libxml2 版本 2.9.2,启用了 xml 读写器和 Zend Extension 220131226。 这是有问题的代码,我把这些部分拉出来了,仍然有同样的错误,所以我知道这不是我的字符串格式。 同样可能相关的是,在两台服务器上,文档都以“阅读模式”而不是“打印布局”打开。我希望它在打印布局中打开。
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$phpWord->getCompatibility()->setOoxmlVersion(15);
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
header("Content-Description: File Transfer");
header('Content-Disposition: attachment; filename="' . $client->last_name . '.docx"');
header('Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document');
header('Content-Transfer-Encoding: binary');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Expires: 0');
$objWriter->save("php://output");
【问题讨论】: