我无法使用python-docx库将文本方向(注意:不是文本对齐)设置为从右到左。你有解决这个问题的主意吗?
from docx import Document
from docx.enum.style import WD_STYLE_TYPE
from docx.enum.text import WD_TAB_ALIGNMENT,WD_PARAGRAPH_ALIGNMENT
doc = Document()
style = doc.styles.add_style('rtl', WD_STYLE_TYPE.CHARACTER)
style.font.rtl = True
paragraph = doc.add_paragraph()
paragraph.paragraph_format.alignment = WD_PARAGRAPH_ALIGNMENT.RIGHT
paragraph.add_run('تست Test تست Test',style = "rtl")
doc.save('test.docx')
答案 0 :(得分:0)
我首先调用一个带有 rtl 的模板文档(正常样式是 rtl、阿拉伯字体等)
doc = Document(template_path)
p = doc.add_paragraph()
r = p.add_run()
font = r.font
font.complex_script = True
font.rtl = True
r.add_text(text)