Python docx Lib Center对齐图像

时间:2014-10-20 20:41:02

标签: python image center docx

我正在使用https://python-docx.readthedocs.org/en/latest/

构建自动报告程序

我试图将照片集中在一起,甚至尝试了我在谷歌某处阅读的这个技巧:

document.add_picture('C:\Users\Public\Pictures\Picture.jpg',height=Inches(3.44)) last_paragraph = document.paragraphs[-1] last_paragraph.style = 'centerstyle'

没有运气......

那里的任何人想出办法绕过这个?

1 个答案:

答案 0 :(得分:19)

你可以这样做。

from docx import Document
from docx.enum.text import WD_ALIGN_PARAGRAPH

my_image = document.add_picture('path/to/image') 
last_paragraph = document.paragraphs[-1] 
last_paragraph.alignment = WD_ALIGN_PARAGRAPH.CENTER

我知道我现在可能很晚才回复,但也许对其他人有帮助。

相关问题