如何正确缩进python-docx?

时间:2015-06-01 22:57:45

标签: 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')

1 个答案:

答案 0 :(得分:4)

原来这是文档错误。

如果您使用新API,则可以使用:

paragraph.paragraph_format.left_indent = Inches(0.25)

由于left_indent和{{1}使用了paragraph_format类,ParagraphFormat属性已移至Paragraph“子对象”对象。

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

相关问题