Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python-docx detect enumerated list

i would like to detect enumerated list in a word document using python-docx. like

if paragraph is enum:
  #do something

Is it possible in python-docx?

TIA

like image 508
user2401464 Avatar asked Apr 28 '26 06:04

user2401464


1 Answers

This might be an incomplete answer, but most of the enums or numbered lists have numbering properties reference (w:numPr) property within paragraph properties (w:pPr).

This code is listing all paragraphs which contain w:numPr within w:pPr:

[p for p in doc.paragraphs if len(p._element.xpath('./w:pPr/w:numPr')) > 0]

Hope this helps,

Best

like image 66
aleksandarbos Avatar answered Apr 30 '26 20:04

aleksandarbos