0

I need to write into a docx file from python (which i'm a bit new at) but i have to do it written rtl. After days of googling, the best I could do is this:

from docx import Document
from docx.enum.text import WD_PARAGRAPH_ALIGNMENT as WD_STYLE_TYPE
from docx.shared import Pt
from docx.shared import Inches, Pt

# create docx file
document = Document()
# create paragraph
para = document.add_paragraph()
# create run
run = para.add_run("Hello World")
# create style
mystyle = document.styles.add_style("mystyle", 2)
run.style = mystyle
font = run.font
font.rtl = True # SET RIGHT TO LEFT


document.save(r"C:\Users\USER\Desktop\Code\TofesEfes\WordTes.docx")

the problem is that for some reason the code just ignores this line:

font.rtl = True # SET RIGHT TO LEFT

If I try to change it to:

font.bold = True # SET FONT TO BOLD

the font will come out bold.

I also tried changing the text to be in a rtl languge and nothin changed.

Does anyone here have any idea why it's doing this?

yonris
  • 1
  • Surely the best people who can answer these are the folks that look at https://github.com/python-openxml/python-docx/issues - did you ask there, first? If not, have you asked there at all? If not: if open source isn't behaving the way its documentation says it should, please remember to file an issue so that the people who _make_ that open source are aware of the fact that they either have a bug, or incomplete documentation, so they can fix that for everyone. – Mike 'Pomax' Kamermans Sep 20 '20 at 21:27
  • Have you come across this SO question in your research? https://stackoverflow.com/questions/41985320/python-docx-set-the-text-direction-rtl – scanny Sep 20 '20 at 23:12

0 Answers0