1

I'm working with a document that has a custom Style that has a custom bulleted list style applied to it. I need to be able to inspect this style and understand that it is a bulleted list. Is there a property of the style that would be associated with this? I've been looking at the the properties within the paragraph format like so:

document = Document('example.docx')
styles = document.styles
for style in style:
    print(dir(style.paragraph_format))

but none of these objects that I've looked at thus far make it clear that there's a bulleted list style. Is this information stored somewhere? As I said, the name of the style is custom and so isn't named as some built-in List Bullet style or anything like that.

gammapoint
  • 1,083
  • 2
  • 15
  • 27

1 Answers1

2

There is currently no API support in python-docx for detecting this condition. You would need to inspect the XML of the style and you may need to walk through a few references as there is potentially some inheritance involved.

I'd recommend starting with a paragraph style you know has bullets applied and print(style._element.xml) and see what you can make out by way of an element is "number" in its name or whatever hints you can find.

I will tell you that list formatting is a complex matter in Word. You can probably find some other resources on search that may give clues, this one came up on a quick searh: Bullet Lists in python-docx

scanny
  • 26,423
  • 5
  • 54
  • 80
  • 1
    Appreciate your help, @scanny. I did in fact run through some examples and for the ones I looked at, detecting the `numId` attribute was a decent clue as to whether I was working with some sort of list style. Understanding precisely what that value means in the context of the document is another matter, but perhaps not one that I need for my narrow use case. I appreciate you letting me know that there's no other obvious way. – gammapoint Dec 18 '21 at 04:39