2014-10-20 115 views
5

我建立使用https://python-docx.readthedocs.org/en/latest/Python的DOCX庫中心對齊圖像

我試圖居中的圖片,甚至嘗試這一招,我在谷歌的地方讀了自動報告程序:

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

沒有運氣...

任何人都想出了一種方法來解決這個問題?

回答

9

你可以做這樣的事情。

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 

我知道我現在可能會回答很晚,但也許這有助於其他人。

+0

是的,它確實幫助至少一個人,謝謝你的努力! – 2015-06-16 20:44:34