I have a question: How do add header (and footer) in *.docx file? I use library python-docx in my django project. But it really can't add header. I found solution on stack (July 2012) with using 'win32com', but nowadays it don't work for me. Help me advice. Thank you. Have a nice day.
Add header in *.docx word file using python
741 Views Asked by user233057 At
1
There are 1 best solutions below
Related Questions in PYTHON
- Upload a document to a SharePoint document library (can be via Rest Api/other) using C# & also retrieve the unique id of the document
- Sharepoint alers email deletion from alerts
- SharePoint/CSS3 Gradients/IE9
- Sharepoint 2007 / Jquery - Replace all text on body or render HTML
- share point excel service
- MS Access Run-time error 3999
- Maintain Sharepoint Server Url with subfolders in document list
- How can I integrate a SharePoint document folder in a separate ASP.NET web site?
- why I don't get list subfolders despite using RecursiveAll option
- Modal Extender Ajax Control Toolkit (ASP 2.0) will not pop-up on server side trigger
Related Questions in DJANGO
- Upload a document to a SharePoint document library (can be via Rest Api/other) using C# & also retrieve the unique id of the document
- Sharepoint alers email deletion from alerts
- SharePoint/CSS3 Gradients/IE9
- Sharepoint 2007 / Jquery - Replace all text on body or render HTML
- share point excel service
- MS Access Run-time error 3999
- Maintain Sharepoint Server Url with subfolders in document list
- How can I integrate a SharePoint document folder in a separate ASP.NET web site?
- why I don't get list subfolders despite using RecursiveAll option
- Modal Extender Ajax Control Toolkit (ASP 2.0) will not pop-up on server side trigger
Related Questions in MS-WORD
- Upload a document to a SharePoint document library (can be via Rest Api/other) using C# & also retrieve the unique id of the document
- Sharepoint alers email deletion from alerts
- SharePoint/CSS3 Gradients/IE9
- Sharepoint 2007 / Jquery - Replace all text on body or render HTML
- share point excel service
- MS Access Run-time error 3999
- Maintain Sharepoint Server Url with subfolders in document list
- How can I integrate a SharePoint document folder in a separate ASP.NET web site?
- why I don't get list subfolders despite using RecursiveAll option
- Modal Extender Ajax Control Toolkit (ASP 2.0) will not pop-up on server side trigger
Related Questions in DOCX
- Upload a document to a SharePoint document library (can be via Rest Api/other) using C# & also retrieve the unique id of the document
- Sharepoint alers email deletion from alerts
- SharePoint/CSS3 Gradients/IE9
- Sharepoint 2007 / Jquery - Replace all text on body or render HTML
- share point excel service
- MS Access Run-time error 3999
- Maintain Sharepoint Server Url with subfolders in document list
- How can I integrate a SharePoint document folder in a separate ASP.NET web site?
- why I don't get list subfolders despite using RecursiveAll option
- Modal Extender Ajax Control Toolkit (ASP 2.0) will not pop-up on server side trigger
Related Questions in WIN32COM
- Upload a document to a SharePoint document library (can be via Rest Api/other) using C# & also retrieve the unique id of the document
- Sharepoint alers email deletion from alerts
- SharePoint/CSS3 Gradients/IE9
- Sharepoint 2007 / Jquery - Replace all text on body or render HTML
- share point excel service
- MS Access Run-time error 3999
- Maintain Sharepoint Server Url with subfolders in document list
- How can I integrate a SharePoint document folder in a separate ASP.NET web site?
- why I don't get list subfolders despite using RecursiveAll option
- Modal Extender Ajax Control Toolkit (ASP 2.0) will not pop-up on server side trigger
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular # Hahtags
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Courtest of edi9999 I think the best way you can take is looking at python-docx to see how it manages the files. Docx is a zipped format (Docx Tag Wiki):
The
.docx
format is a zipped file that contains the following folders:A library like docx-python extracts at first the docx, so you could find it in the python docx: I have found it for you: https://github.com/mikemaccana/python-docx/blob/master/docx.py#L65
You can get the xmlcontent of 'word/document.xml' which is the main content of the docx, change it either using docx-python (which I recommend to you, docx-python seems to be able to add many different elements. If you want to copy the content of an other word document at the beginning of the document, you could probably try to copy the content of the document.xml to your document.xml, but It will probably give you some errors, specially if you use Images or non-text content.
To add a header or a footer, you will have to create a file
word/header1.xml
or aword/footer1.xml
You could just copy the header1.xml content of a file you created, this should work.Hope this helps