我想使用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;有什么建议吗?为什么我的代码不起作用?
发布于 2019-09-20 13:32:06
尝试以下内容标题:
header('Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document');https://stackoverflow.com/questions/58029195
复制相似问题