/**
* @param $param
* @throws \PhpOffice\PhpWord\Exception\CopyFileException
* @throws \PhpOffice\PhpWord\Exception\CreateTemporaryFileException
* 生成教学word
*/
public function testDataToWord($param){
$data = json_decode(ExcelToWordService::$data,true);//数据
$document = new TemplateProcessor('/home/work/XXXX/Lesson_plan_module_10_1_3.docx');//模板地址
Settings::setOutputEscapingEnabled(true);//输出转义
$document->setValue('course_theme', $data[3][2]);
$document->setValue('course_time', $data[5][2]);
$document->setValue('course_target', $data[6][2]);
$document->setValue('course_focus', $data[7][2]);
$document->saveAs('./target.docx');
ob_clean();
ob_start();
$fp = fopen('./target.docx',"r");
$file_size = filesize('./target.docx');
Header("Content-type:application/octet-stream");
Header("Accept-Ranges:bytes");
Header("Accept-Length:".$file_size);
Header("Content-Disposition:attchment; filename=".'XXXX.docx');//生成的word名称
$buffer = 1024;
$file_count = 0;
while (!feof($fp) && $file_count < $file_size){
$file_con = fread($fp,$buffer);
$file_count += $buffer;
echo $file_con;
}
fclose($fp);
ob_end_flush();
}
问题1,在替换中会遇到转义字符输出错乱的情况,加上如下代码就OK了……
\PhpOffice\PhpWord\Settings::setOutputEscapingEnabled(true);
本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!