如何使用pythondocx正确缩进?

2024-06-11 00:00:27 发布

您现在位置:Python中文网/ 问答频道 /正文

缩进看起来非常简单,终端会打印回正确的缩进,但相同的缩进不会反映在我保存的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')

Tags: fromimportadd终端leftdocumentwordshared
1条回答
网友
1楼 · 发布于 2024-06-11 00:00:27

这是一个文档错误

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

paragraph.paragraph_format.left_indent = Inches(0.25)

ParagraphParagraphStyle对象都使用ParagraphFormat类时,left_indent属性被移到了paragraph_format子对象,这是一对夫妇释放回来的

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

相关问题 更多 >