question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

feature: Document.headers and footers

See original GitHub issue

It would be incredibly useful to be able to get the page headers through Document.headers, or similar.

For now, I use a very ugly hack to get alll header texts:

def get_headers(file):
    import xml.etree.ElementTree as ET
    document = Document(file)
    namespace = dict(w="http://schemas.openxmlformats.org/wordprocessingml/2006/main")
    header_uri = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/header"
    headers = []
    for rel, val in document._document_part._rels.iteritems():
        if val._reltype == header_uri:
            xml = val._target._blob
            root = ET.fromstring(xml)
            text_element = root.find(".//w:t", namespace)
            if text_element.text is not None:
                headers.append(text_element.text)
    return headers

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Reactions:4
  • Comments:45 (14 by maintainers)

github_iconTop GitHub Comments

8reactions
eismogcommented, May 27, 2016

@scanny

I have lots of docx, and I want to replace these docx header’s text Is there any way to do it?

Thanks

3reactions
scannycommented, May 27, 2016

This feature set is under active development by @eupharis on this pull request: #291

I don’t believe there’s a workaround at the moment, it would need to be a pretty hairy one given the involvement of new parts, but would certainly be possible. You can look at the analysis documents on that branch to get an idea what’s involved.

And of course encouragement/+1s on that PR is always helpful in keeping spirits high as we move the development along 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Word 2016: Headers and Footers - GCF Global
Headers and footers generally contain additional information such as page numbers, dates, an author's name, and footnotes, which can help keep longer documents...
Read more >
Insert a header or footer - Microsoft Support
Go to Insert > Header or Footer. · Choose from a list of standard headers or footers, go to the list of Header...
Read more >
Headers and Footers in Microsoft Word
Headers and footers are useful for including material that you want to appear on every page of a document such as your name,...
Read more >
Using Headers and Footers - Suzanne S. Barnhill
As mentioned above, even if you think your document doesn't yet have a header or footer, you have to use View | Header...
Read more >
Sections / Headers and Footers in Microsoft Word
A header or footer is text or other information such as graphics that is stored at the top or bottom of the page...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found