Python docx Lib Center Image Alignment

I am creating an automated reporting program using https://python-docx.readthedocs.org/en/latest/

I try to focus the image and even tried this trick I read somewhere on google:

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

no luck ...

Has anyone out there figured out a way around this?

+5
source share
1 answer

You can do something like this.

 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 

I know that I probably answer recently, but maybe this helps someone else.

+9
source

Source: https://habr.com/ru/post/1205129/


All Articles