pqzx / html2docx

Convert html to docx
MIT License
69 stars 49 forks source link

Tab_stops #33

Closed finevine closed 2 years ago

finevine commented 2 years ago

Hi, Is there a way to add tab_stops ? I manage to add them in the style but not in the html.

    tab_stops = document.styles['Normal'].paragraph_format.tab_stops
    tab_stop = tab_stops.add_tab_stop(Cm(15), WD_TAB_ALIGNMENT.RIGHT, WD_TAB_LEADER.DOTS)

with this link I think it's possible : https://python-docx.readthedocs.io/en/latest/api/document.html#docx.document.Document.add_paragraph I've tried to add an html comment and replace it by a `\t``

html = html.replace('<!--TAB-->', '\t')

But it doesn't work so far.

Thanks!

finevine commented 2 years ago

I've manage to achieve what I wanted:

    # add tabs
    for p in document.paragraphs:
        if p.text.find("[!TAB]") > 0:
            p.text = p.text.replace("[!TAB]", "\t")

I add in my template [!TAB] and replace it with python with \t

pqzx commented 2 years ago

Glad you were able to solve it!