首页 > 解决方案 > 在已经存在的 docx 文档的开头添加图像

问题描述

此代码说明了如何将图像添加到 .docx 文档中,通过创建一个新文档并向其中添加内容,我的文档中只有一页内容很少,我如何在此数据中添加一个图像?换句话说我希望图像成为文档中的第一个项目,然后是文档中已有的项目。

from docx import Document
from docx.shared import Inches

document = #Path to my already existing docx that has one table in it.
document.add_picture('/tmp/foo.jpg') #Will add a picture at the end of the doc, but I want this picture at the very beginning before the other content
document.save('demo.docx')

我检查了大多数讨论“在特定 docx 位置添加图像”的问题,但它们似乎都在将图像添加到新文档中

标签: pythonpython-docx

解决方案


推荐阅读