如何在python-docx中正确缩进?

4

缩进看起来很简单,终端打印出正确的缩进,但是保存在我的 Word 文档中的缩进却没有反映出来。
这里我做错了什么吗?

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')
1个回答

8
这实际上是一份文档错误。
如果使用新的API,它可以正常工作:
paragraph.paragraph_format.left_indent = Inches(0.25)

left_indent属性在几个版本之前已经移到了paragraph_format "子对象"中,因为ParagraphFormat类被ParagraphParagraphStyle对象同时使用。

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


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接