如何使用 python-docx 正确缩进?

j4w*_*j4w 4 python python-docx

缩进看起来非常简单,终端会打印回正确的缩进,但相同的缩进没有反映在我保存的 Word docx 中。
我在这里做错了什么吗?

from docx import Document
from docx.shared import Inches
    
worddoc = Document()
paragraph = worddoc.add_paragraph('Left Indent Test')
paragraph.left_indent = Inches(.25)
print(paragraph.left_indent.inches)
    
worddoc.save('left_indent.docx')
Run Code Online (Sandbox Code Playgroud)

sca*_*nny 8

事实证明这是一个文档错误。

如果您使用新的 API,它会起作用:

paragraph.paragraph_format.left_indent = Inches(0.25)
Run Code Online (Sandbox Code Playgroud)

当该类被和对象使用时,该left_indent属性被移动到paragraph_format几个释放回来的“子对象” 。ParagraphFormatParagraphParagraphStyle

如果您在 GitHub 上的问题跟踪器中提交错误报告,python-docx我们将在下次访问时更新文档。