I am trying to enable "Repeat Header Rows" for a table row
@ssuzen
Hi, sorry for the delay. This is a snippet you could use:
def set_repeat_table_header(row):
""" set repeat table row on every new page
"""
tr = row._tr
trPr = tr.get_or_add_trPr()
tblHeader = OxmlElement('w:tblHeader')
tblHeader.set(qn('w:val'), "true")
trPr.append(tblHeader)
return row
Thank you. This works just fine. I appreciate it.
Hi, could you provide a small example of how you would implement that function? When and where would you call it when you create the table?
Thanks!
@pierreluc-plt If you have a table, you can call set_repeat_table_header(table.rows[0]) for the setup.
Just cross-posting the required import statements for this from here:
import docx
from docx.oxml import OxmlElement
from docx.oxml.ns import qn
Hi,
could you clarify one thing. Would you use this function after a Table created? Or after it is filled out?
Would really appreciate an example cuz so far it didnt work out. Thanks in advance!
Most helpful comment
@ssuzen
Hi, sorry for the delay. This is a snippet you could use:
def set_repeat_table_header(row): """ set repeat table row on every new page """ tr = row._tr trPr = tr.get_or_add_trPr() tblHeader = OxmlElement('w:tblHeader') tblHeader.set(qn('w:val'), "true") trPr.append(tblHeader) return row