更新时间:2023-10-09 14:20:10
引用 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.
当我们深入挖掘"时,我们会发现 Run.add_picture()
API.
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')