4

缩进看起来很简单,终端打印出正确的缩进,但相同的缩进并没有反映在我保存的 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')
4

1 回答 1

5

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

如果您使用新的 API,它可以工作:

paragraph.paragraph_format.left_indent = Inches(0.25)

left_indent属性被移动到paragraph_format“子对象”,几个释放回来,因为ParagraphFormat该类被ParagraphParagraphStyle对象使用。

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

于 2015-06-02T02:00:13.220 回答