Skip to content

Correctly reading enumeration and list numbers/letters #1454

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
renatodamas opened this issue Dec 12, 2024 · 3 comments
Open

Correctly reading enumeration and list numbers/letters #1454

renatodamas opened this issue Dec 12, 2024 · 3 comments

Comments

@renatodamas
Copy link

renatodamas commented Dec 12, 2024

Similar to #1443, but when reading from a docx file. Other related issues: #1187, #1313, #1012, #1007, #987, #971, #677, #639, #614, #600, #590, #511, #554, #536, #471, #217, #180, #87, #25

Python-docx is not reading the enumeration of paragraph and other elements correctly.

I'm ready to get to work on it. I just need some technical guidance.

I would be grateful for any assistance.

related links:
Stack Overflow: Getting the List Numbers of List Items in docx file using Python-Docx

@renatodamas renatodamas changed the title Correct reading enumeration and list numbers/letters Correctly reading enumeration and list numbers/letters Dec 12, 2024
@Canx
Copy link

Canx commented Mar 26, 2025

Maybe related with this line:

raise NotImplementedError

@Canx
Copy link

Canx commented Mar 26, 2025

This is what chatgpt suggests (not tested):

from ..oxml import parse_xml, nsdecls
...

@classmethod
def new(cls):

    numbering_xml = parse_xml('<w:numbering {}></w:numbering>'.format(nsdecls('w')))
    return cls(numbering_xml)

@Canx
Copy link

Canx commented Mar 26, 2025

Tested and working with this patch, or at least not giving me exception generating document:

@classmethod
    def new(cls):
        from docx.oxml import parse_xml
        from docx.oxml.ns import nsdecls
        xml_str = '<w:numbering {}></w:numbering>'.format(nsdecls('w'))
        numbering_xml = parse_xml(xml_str)
        content_type = 'application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml'
        partname = '/word/numbering.xml'

        return cls(partname, content_type, numbering_xml, None)

Canx added a commit to Canx/python-docx that referenced this issue Mar 26, 2025
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