PHPWord-损坏的Word文件

时间:2019-09-20 13:19:00

标签: php phpword phpoffice

我想使用PHPWord从现有模板下载word文件。 我尝试了这段代码,但它生成了损坏的文件:

$file = ROOT . '/web/templates/recu.docx';
$PHPWord = new \PhpOffice\PhpWord\TemplateProcessor($file);

$PHPWord->setValue('Value1', date('d/m/Y'));
$PHPWord->setValue('Value2', "ffff");
$PHPWord->setValue('Value3', "sabrine");
$PHPWord->setValue('Value4', utf8_decode("555555"));
$PHPWord->setValue('Value5', "200000");

$new_file = "recu_".date('d_m_Y_H_i');
$PHPWord->saveAs(ROOT. '/web/uploads/recu/'.$new_file.'.docx');

header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment;filename="'.$new_file.'.docx"');

$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($PHPWord, 
'Word2007');
ob_clean();
$objWriter->save('php://output');
exit;

我的代码为什么不起作用的任何建议?

1 个答案:

答案 0 :(得分:0)

尝试使用此内容标题:

.as-console-wrapper { top: 0; max-height: 100% !important; }