1.composer require phpoffice/phpword
use PhpOffice\PhpWord\TemplateProcessor;
public function word()
{
$doc = new TemplateProcessor('./ceshi.docx');
![模板示例图](https:
$doc->setValue('title', '靳子超');
$doc->setValue('time', '2021-12-31');
$doc->setValue('content', 'hahdhahdjj和附近的肆虐封建割据韩国i恶化给个i俄u换个风格很符合司法就是手机号为旅客列车的活动呢肆虐封建割据韩国i恶化给个i俄u换个风格很符合司法就是手机号为旅客列车的活动呢肆虐封建割据韩国i恶化给个i俄u换个风格很符合司法就是手机号为旅客列车的活动呢肆虐封建割据韩国i恶化给个i俄u换个风格很符合司法就是手机号为旅客列车的活动呢肆虐封建割据韩国i恶化给个i俄u换个风格很符合司法就是手机号为旅客列车的活动呢肆虐封建割据韩国i恶化给个i俄u换个风格很符合司法就是手机号为旅客列车的活动呢');
$doc->saveAs('./ceshi1.docx');
ob_clean();
ob_start();
$fp = fopen('./ceshi1.docx', "r");
$file_size = filesize('./ceshi1.docx');
Header("Content-type:application/octet-stream");
Header("Accept-Ranges:bytes");
Header("Accept-Length:" . $file_size);
Header("Content-Disposition:attchment; filename=" . '测试文件.docx');
$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();
}
|