如何使用XY坐标将图像或文本添加到现有的word和excel文件中?

发布于 2025-01-13 20:54:40 字数 743 浏览 2 评论 0原文

我正在尝试使用以下库将特定 XY 坐标处的图像添加到我的 Microsoft Word 文档和 Excel 文件中

https://github .com/PHPOffice/PHPWord

我已完全阅读该文档,但我无法找到如何提供 X,Y 位置以在现有的 word 或 excel 文件中添加图像?

这是我的代码。它正在生成新文档,但我想在现有文档中添加图像。

$phpWord = new \PhpOffice\PhpWord\PhpWord();

$section = $phpWord->addSection();

$section->addImage('abc.png',array('width' => 650, 'height' => 365));


header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment;filename="test.docx"');

$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
$objWriter->save('php://output');

您能建议我们如何做到这一点的任何方法或解决方案吗?谢谢

I am trying to add image at particular XY coordniate to my microsoft word doc and excel file using following library

https://github.com/PHPOffice/PHPWord

I have read the doc completely but i can not able to find how to provide X,Y position to add image in the existing word or excel file ?

here is my code. which is generating new doc but i wanted to add image in the existing doc.

$phpWord = new \PhpOffice\PhpWord\PhpWord();

$section = $phpWord->addSection();

$section->addImage('abc.png',array('width' => 650, 'height' => 365));


header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment;filename="test.docx"');

$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
$objWriter->save('php://output');

can you please suggest any way or solution that how we can do it? Thanks

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

错々过的事 2025-01-20 20:54:40

您可以设置图像位置:

这里有关 addImage 的更多信息

$section->addImage($src, [$style]);

喜欢你用 ['width' =>; 做了650]

您可以添加 marginLeft 作为数组键,它将是您的 x 值:

$section->addImage('abc.png',array('width' => 650, 'height' => 365, 'marginLeft': 100));

You can set image location:

here more information about addImage

$section->addImage($src, [$style]);

Like you did with ['width' => 650]

You can add marginLeft as array key it will be your x value:

$section->addImage('abc.png',array('width' => 650, 'height' => 365, 'marginLeft': 100));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文