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
764 Views Asked by user233057 At
1
There are 1 best solutions below
Related Questions in PYTHON
- new thread blocks main thread
- Extracting viewCount & SubscriberCount from YouTube API V3 for a given channel, where channelID does not equal userID
- Display images on Django Template Site
- Difference between list() and dict() with generators
- How can I serialize a numpy array while preserving matrix dimensions?
- Protractor did not run properly when using browser.wait, msg: "Wait timed out after XXXms"
- Why is my program adding int as string (4+7 = 47)?
- store numpy array in mysql
- how to omit the less frequent words from a dictionary in python?
- Update a text file with ( new words+ \n ) after the words is appended into a list
- python how to write list of lists to file
- Removing URL features from tokens in NLTK
- Optimizing for Social Leaderboards
- Python : Get size of string in bytes
- What is the code of the sorted function?
Related Questions in DJANGO
- Display images on Django Template Site
- Protractor did not run properly when using browser.wait, msg: "Wait timed out after XXXms"
- Django invalid literal for int() with base 10:
- Removing URL features from tokens in NLTK
- Django Noob URL to from Root Page to sub Page
- Django Admin tables not displaying correctly
- Django with chartkick
- Django urls.py not rendering correct template
- django form errors before submit
- django admin: custom app_index with context
- Display multiple models in one view in Django
- Unexpected NoReverseMatch error when using include() in urls patterns
- Search for a key in django.core.cache
- Django webapp (on an Apache2 server) hangs indefintely when importing nltk in views.py
- Django flush won't load fixtures
Related Questions in MS-WORD
- Cannot open xml file
- How to programatically implement Columns in page layout as of in MS Word using python-docx
- In which field the cursor is? (ms word, vba)
- load word file (.docx) in richtextbox
- Replace hyperlink with text from linked document
- Embedding Image in Microsoft Word using ColdFusion
- Using array in for cycle in Word Interop
- Runtime Error '5941' The Requested Member of Collection Does Not Exist
- Insert a photo to a Word bookmark from an Excel range, VBA
- How to choose a different header image in MS Word 2013 using a macro/button
- Can we edit hyperlink in Restrict editing mode in Word 2013?
- Macro in Word to Underline each paragraph in document less than X characters long
- Need to capture current scroll position (not cursor position) in MS Word
- Apply style on Content Control in a Word Document using OpenXML
- ActiveDocument.Tables.Count returns 0 but there are 4 tables
Related Questions in DOCX
- Reading from a word document using java
- Reading docx files, recognizing and storing italicized text
- How to create a "VALID DOCX" using Coldfusion?
- Mathematics not working when converting from LaTeX to docx (through markdown) using pandoc
- Illegal exception zip file is closed in apache poi for docx file creating after build as jar
- How to identify if a paragraph lands on a page break in Apache POI
- batch file for runing a java command
- Remove cells from word table with Novacode DocX
- How can i delete a bookmark using docx4j?
- Loading text from .docx to MySQL using Python-docx
- How to create tab stops using Novacode-Docx library?
- Write a function in R to process docx files
- Read and replace contents in .docx (Word) file
- Open docx file with password?
- PHP - Laravel - Convert .docx to PDF format
Related Questions in WIN32COM
- printing pdf file on printer using c++
- Handle Outlook Send Event in Python
- Create SAFEARRAY of Strings in Python
- Creating pivot table in Python then exporting to excel
- pythoncom error invoking COM method excel new sheet
- Python thread: The application called an interface that was marshalled for a different thread
- Pass the variable `Nothing` using Python's `win32com`
- python add data to existing excel cell Win32com
- wait user close Excel in python
- How to insert a picture into Excel at a specified cell position
- Python win32com Excel.Application throws error if cursor is in a cell when 'visible' is set to False
- changing chart size in Excel from Python win32com
- win32com Excel.Application can't open documents anymore
- After windows update getting this error AttributeError: olEmbeddeditem
- Add header in *.docx word file using python
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 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
.docxformat 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.xmlor aword/footer1.xmlYou could just copy the header1.xml content of a file you created, this should work.Hope this helps