Python-docx: How to set a table row to repeated as header?

Created on 4 Oct 2016  路  6Comments  路  Source: python-openxml/python-docx

I am trying to enable "Repeat Header Rows" for a table row

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

All 6 comments

@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!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

achillis1 picture achillis1  路  5Comments

bendaojiu picture bendaojiu  路  5Comments

sskadit picture sskadit  路  4Comments

scanny picture scanny  路  8Comments

norecces picture norecces  路  7Comments