【发布时间】:2018-09-26 10:18:19
【问题描述】:
我正在尝试使用 python-docx 将一些文本写入 docx 文件。我想将文本从右到左对齐,并为此添加了一种样式,但这是行不通的。
代码如下:
from docx.enum.style import WD_STYLE_TYPE
missingwords= Document()
styles = missingwords.styles
style = missingwords.styles.add_style('rtl', WD_STYLE_TYPE.PARAGRAPH)
style.font.rtl = True
paragraph =missingwords.add_paragraph("Hello world",style='rtl')
【问题讨论】:
-
你看过this question吗?
-
是的,它使用该解决方案。但我必须在添加每个段落后添加“paragraph.alignment = 0”。所以我试图找到一个更好的解决方案来减少代码行。
标签: python python-3.x docx python-docx