更新时间:2023-10-09 13:41:16
引用 python-docx文档:
Document.add_picture()方法将指定的图片添加到文档末尾的自己的段落中.但是,通过对API进行更深入的研究,您可以将文本放在图片段落的任一侧,或同时放置在这两个段落中.
The Document.add_picture() method adds a specified picture to the end of the document in a paragraph of its own. However, by digging a little deeper into the API you can place text on either side of the picture in its paragraph, or both.
When we "dig a little deeper", we discover the Run.add_picture()
API.
以下是其用法示例:
from docx import Document
from docx.shared import Inches
document = Document()
p = document.add_paragraph()
r = p.add_run()
r.add_text('Good Morning every body,This is my ')
r.add_picture('/tmp/foo.jpg')
r.add_text(' do you like it?')
document.save('demo.docx')