Skip to content

Add numbering to heading #1012

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
arun-kol opened this issue Sep 27, 2021 · 1 comment
Open

Add numbering to heading #1012

arun-kol opened this issue Sep 27, 2021 · 1 comment

Comments

@arun-kol
Copy link

I wanted to add heading level numbering such as 1, 1.1, 1.1.1 for headings 1, 2 and 3 respectively.
I found this thread from two years ago that says that it has not been implemented yet.
https://stackoverflow.com/questions/53870457/python-docx-how-to-number-headings
Is there any workaround for this or is the fix done?

@rvmtz
Copy link

rvmtz commented Nov 7, 2024

@arun-kol , know this is an old one, but here's my workaround:

def list_number(paragraph):
    paragraph._element.get_or_add_pPr().get_or_add_numPr().get_or_add_ilvl().val = 0
    paragraph._element.get_or_add_pPr().get_or_add_numPr().get_or_add_numId().val = 10
    
# doc = ...

list_number(doc.add_paragraph(name, style="Heading 1"))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants