Hướng dẫn python-docx runs
I'm trying to automate the creation of .docx files (WordML) with the help of python-docx (https://github.com/mikemaccana/python-docx). My current script creates the ToC manually with following loop:
Does anyone know of a way to use the "word built-in" ToC-function, which adds the index automatically and also creates paragraph-links to the individual chapters? Thanks a lot! asked Sep 3, 2013 at 15:17 The key challenge is that a rendered ToC depends on pagination to know what page number to put for each heading. Pagination is a function provided by the layout engine, a very complex piece of software built into the Word client. Writing a page layout engine in Python is probably not a good idea, definitely not a project I'm planning to undertake anytime soon :) The ToC is composed of two parts:
Creating the element is pretty straightforward and relatively low-effort. Creating the actual visible content, at least if you want the page numbers included, requires the Word layout engine. These are the options:
Here's a very nice set of screencasts by Eric White that explain all the hairy details Mad Physicist 100k24 gold badges163 silver badges246 bronze badges answered Sep 3, 2013 at 23:27 1 Sorry for adding comments to an old post, but I think it may be helpful. This is not my solution, but it has been found there: https://github.com/python-openxml/python-docx/issues/36 Thanks to https://github.com/mustash and https://github.com/scanny
answered Feb 5, 2018 at 12:09 5 @Mawg // Updating ToC Had the same issue to update the ToC and googled for it. Not my code, but it works:
answered Mar 14, 2019 at 11:34 1 For creating Automatic Table of Contents in Word using python:
#Thanks answered Dec 4, 2019 at 7:08 3 |