Search code examples
python-docx

How can I get the ListNumber in a docx by using python-docx


I am trying to get the style of each paragraph in a docx by using "paragraph.style.name".

However, I can only get:

           "Heading 1"
           "Heading 2"
            "Normal"
            "Normal"
               .
               .

but no "List 1", "List 2" as expected.

How to get the ListNumber of a listed paragraph? Or any other style information can I get except "Normal"?


Solution

  • This is probably due to the list numbering being applied manually using the toolbar icon rather than by using a style. In this case the style would be unchanged, which would explain why it might appear as "Normal".

    The list numbering details will be found in the paragraph properties and will involve several references to the numbering.xml part. Your best bet if you want to tackle it would be to start by browsing the XML; opc-diag is good for that.

    But it's pretty complicated and I know of no examples you can follow.