5

I want to access to a paragraph or run that has a unique font or font-size using python-docx. How i can get texts of runs or paragraphs that has specified font or font-size?

YowE3K
  • 23,852
  • 7
  • 26
  • 40
keramat
  • 4,328
  • 6
  • 25
  • 38

1 Answers1

5

For any one that want to know:

for paragraph in doc.paragraphs:
    for run in paragraph.runs:
        if run.font.size == Pt(16):
            print(paragraph.text)
keramat
  • 4,328
  • 6
  • 25
  • 38
  • This code returns None for me. Any suggestions?\ – Navi Jun 09 '21 at 06:45
  • Take a look at [this answer](https://stackoverflow.com/questions/76650844/find-all-the-texts-which-is-normal-style-and-font-size-is-not-11-in-a-docx-fil/76651650#76651650) – andexte Jul 10 '23 at 07:46