【问题标题】:Python docx Lib Center Align imagePython docx Lib 中心对齐图像
【发布时间】:2014-12-15 23:03:38
【问题描述】:

我正在使用 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'

没有运气......

有人想出办法解决这个问题吗?

【问题讨论】:

    标签: python image center docx


    【解决方案1】:

    你可以这样做。

    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
    

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

    【讨论】:

    • 是的,它确实至少帮助了其他人,感谢您的努力!
    • 这确实帮助了我。谢谢! ?
    • 我也是,应该被标记为答案。挑剔:无需定义my_image 变量。
    • 不得不使用 WD_PARAGRAPH_ALIGNMENT 但效果相同。
    猜你喜欢
    • 1970-01-01
    • 2013-08-19
    • 1970-01-01
    • 1970-01-01
    • 2018-09-27
    • 2013-09-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多