Skip to content

feature: Document.headers and footers #104

Description

@rotsee

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions