是否可以在 python-docx 中垂直和水平对齐段落?

Is it possible to align a paragraph vertically and horizontally in python-docx?

我知道您可以使用 WD_ALIGN_PARAGRAPH 水平对齐段落,我只是想知道是否可以在 Word 中执行类似的操作:"Layout > Align > Align Middle" 将文档中的文本垂直居中 python-docx.

图书馆目前没有办法做到这一点。但是,我发现通过对齐现有文档中的文本,然后使用 python-docx 打开它,您可以简单地编辑文本,它会保留其格式。

from docx import document

document = Document('template.docx')
# This just grabs the first paragraph, code assumes you've already applied formatting.
document.paragraphs[0].text = "Example Text"
document.save('output.docx')