phpword 无法替换 docx 文件中的现有图像

发布于 2025-01-18 10:45:15 字数 410 浏览 3 评论 0原文

我正在尝试使用下面的代码替换word文件中的现有图像。当我保存输出文件时,它具有旧图像。

我打开 Word 文件并粘贴 1.png 图像,然后尝试将 1.png 替换为 2.jpg 但它没有执行任何操作。我尝试过很多解决方案,但没有找到任何永久的好的解决方案。

$templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor($source_file);
$image_path = '2.jpg';
$templateProcessor->setImageValue('1.png', '2.jpg');
$templateProcessor->saveAs('output.docx');

版本“phpoffice/phpword”:“^0.18.3”

I am trying to replace existing image in the word file using below code. when I save the output file was having old image as it is.

I open the word file and paste the 1.png image then I try to replace 1.png with 2.jpg but it is not doing anything. I have tried to see many solutions but I do not found any permanent good solution.

$templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor($source_file);
$image_path = '2.jpg';
$templateProcessor->setImageValue('1.png', '2.jpg');
$templateProcessor->saveAs('output.docx');

version "phpoffice/phpword": "^0.18.3"

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文