如何使用XY坐标将图像或文本添加到现有的word和excel文件中?
我正在尝试使用以下库将特定 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以设置图像位置:
这里有关 addImage 的更多信息
喜欢你用
['width' =>; 做了650]
您可以添加 marginLeft 作为数组键,它将是您的 x 值:
You can set image location:
here more information about addImage
Like you did with
['width' => 650]
You can add marginLeft as array key it will be your x value: