【问题标题】:cannot make text rtl with python-docx无法使用 python-docx 制作文本 rtl
【发布时间】:2022-08-16 16:50:00
【问题描述】:

是的,我知道存在很多关于这个问题的问题,但我无法让它们中的任何一个起作用。

我有 python 3.7 和 python-docx 0.8.11。 我尝试了很多解决方案,包括this one

from docx import Document, enum
document = Document()
mystyle = document.styles.add_style(\'mystyle\', enum.style.WD_STYLE_TYPE.CHARACTER)
run = document.add_paragraph().add_run(text)
run.style = mystyle
font = run.font
font.rtl = True
document.save(\'test.docx\')

from docx import Document, enum
from docx.enum.text import WD_PARAGRAPH_ALIGNMENT

doc = Document()

rtlstyle = doc.styles.add_style(\'rtl\', enum.style.WD_STYLE_TYPE.PARAGRAPH)
rtlstyle.font.rtl = True
p = doc.add_paragraph(text)
p.alignment = WD_PARAGRAPH_ALIGNMENT.RIGHT
p.style = rtlstyle
doc.save(\'test.docx\')

到目前为止没有任何效果

  • i couldn\'t make any of them work 怎么样?错误?不是rtl?提供的两种解决方案有什么区别?预期与实际
  • 没有错误它只是从左到右写
  • 我可以看到两者之间没有区别,只是在其中一种解决方案中对齐是向右的

标签: python python-3.7 right-to-left python-docx


【解决方案1】:

看到这个:https://stackoverflow.com/posts/73133074/revisions

也如提及here 将其放在您的文字之前:u'\u202B' +“您的文字”

或者 u'\u202E' 如果没有工作

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-03
    • 2022-07-04
    相关资源
    最近更新 更多