I am trying to change the style of the header and footer in my word document using python-docx. However, after going through the documentation of header and footer objects I couldn't find the way to change the style. I have attached images to what I want to achieve using python-docx.
This is what I want to achieve - Applied the predefined header style in word manually. Name of the style is "Insight".
This is what I have currently - Here the default style is applied.
This is the style - I simply want to apply this style using python-docx
Is there anyway to change the header and footer style using python-docx.
A header or footer in a Word document does not itself have a style. Rather a paragraph can have a style and a header or footer contains one or more paragraphs.
So the way you format a header with a style is to apply that paragraph style to each of its paragraphs. Many or probably most headers have only a single paragraph.
Be sure you understand this section of the documentation:
https://python-docx.readthedocs.io/en/latest/user/styles-understanding.html
and it's following section here:
https://python-docx.readthedocs.io/en/latest/user/styles-using.html
By default, the paragraph in a new header or footer gets the style "Header" or "Footer" respectively. So you can just make changes to that style and that will change the look of the headers and footers.
If you want to apply a different style you'll need to make sure that style is present in the starting document. This process is explained in the documentation pages linked to above.