Skip to content

Find all the texts which is 'Normal' style and font size is NOT 11 in a docx file using python-docx #1233

Open
@priyamsaha

Description

@priyamsaha
from docx.api import Document
import pandas as pd
from docx.shared import Pt

texts = []
sizes = []
document = Document('new.docx')
for p in document.paragraphs:
    for run in p.runs:
        if p.style.name.startswith("Normal") and run.font.size != Pt(11):
            texts.append(run.text)
print(texts)

I am trying to validate a document, I want all the texts in the document where the font style is 'Normal' and font size is NOT 11. The above code seems to give output where font size is 11 as well. Is there a alternative to this? Thanks in advance!

Metadata

Metadata

Assignees

No one assigned

    Labels

    supportSupport question

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions