public function setWord($name,$png_file){ //$name为文件名 //$png_file为图片路径 //模板的路径 $path=Env::get('root_path').'public/shouquanshu/bule.docx'; //生成word路径 $filePath= './boolWord/'.$name.'.docx'; //声明一个模板对象、读取模板 $templateProcessor = new TemplateProcessor($path); // 替换模板中的变量,对应word里的 ${year} $templateProcessor->setImageValue('image', ['path' => $png_file, 'width' => 100, 'height' => 40, 'ratio' => true]); $templateProcessor->setValue('year',date('Y'));//年 $templateProcessor->setValue('month',date('m'));//月 $templateProcessor->setValue('day',date('d'));//日 //生成新的word $templateProcessor->saveAs($filePath); return $name; }
php 使用phpoffice/phpword 对word指定位置插入字段或者图片
于 2024-01-24 15:19:03 首次发布