1、怎么输出到浏览器(下载用),或者有什么其他的方法?
2、生产的word不要保存在服务器上,怎么做?
3、用下面的代码生成的我惹的文档,不能打开,提示文件损坏,代码:
$PHPWord = new \PHPWord();
$document = $PHPWord->loadTemplate('metter.docx');
$document->setValue('room', $data[0]['room']); //车间 ${room}
$document->setValue('metterNum', $data[0]['metternum']); //故障号 ${metterNum}
$document->setValue('metterClass', $data[0]['metterclass']);//故障类型 ${metterClass}
$document->setValue('station', $data[0]['station']);//地点 ${station}
$document->setValue('major', $data[0]['major']);//专业 ${major}
$document->setValue('knowTime', $data[0]['knowtime']);//接报时间 ${knowTime}
$document->setValue('tellName', $data[0]['tellname']);//汇报人 ${tellName}
$document->setValue('tellTel', $data[0]['telltel']);//汇报电话 ${tellTel}
$document->setValue('content', $data[0]['content']);//内容 ${content}
// Save File
header('Content-Type: application/vnd.ms-word');
header('Content-Disposition: attachment;filename='.$fileName);
header('Cache-Control: max-age=0');
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007');
$objWriter->save('php://output'); // 文件通过浏览器下载
最佳答案