PHP操作word 使用 TemplateProcessor 使用 .docx 文件中添加图像

原创
小哥 4年前 (2022-10-13) 阅读数 1 #PHP
文章标签 PHPword

废话不说,直接上码:

//在你的 templatefile.docx 中必须有一个文本 ${foto} 才能工作

$templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor('templatefile.docx');
$templateProcessor->setImageValue('foto', array('path' => 'dummy_foto.jpg', 'width' => 100, 'height' => 100, 'ratio' => true));
$templateProcessor->saveAs('result.docx');

//打开文件

header("Content-disposition: attachment;filename=" .'result.docx' . " ; charset=iso-8859-1");
echo file_get_contents('result.docx');
版权声明

所有资源都来源于爬虫采集,如有侵权请联系我们,我们将立即删除