Skip to content Skip to sidebar Skip to footer

How To Update Table Of Contents In Docx-file With Python On Linux?

I've got a problem with updating table of contents in docx-file, generated by python-docx on Linux. Generally, it is not difficult to create TOC (Thanks for this answer https://sta

Solution 1:

I found a solution from this [Github Issue][1]. It work on ubuntu.

def set_updatefields_true(docx_path):
    namespace = "{http://schemas.openxmlformats.org/wordprocessingml/2006/main}"
    doc = Document(docx_path)
    # add child to doc.settings element
    element_updatefields = lxml.etree.SubElement(
        doc.settings.element, f"{namespace}updateFields"
    )
    element_updatefields.set(f"{namespace}val", "true")
    doc.save(docx_path)## Heading ##


Post a Comment for "How To Update Table Of Contents In Docx-file With Python On Linux?"