Skip to content

Is there a way to detect line numbers in a Word document using python-docx? #1073

@madden99

Description

@madden99

Hi All,

I am writing some code using using python 3.10.4 and the python-docx library (version 0.8.1.1) on PyCharm (Community Edition 2021.3.3).

The code (as shown in screenshot below and in attached txt file) checks if paragraphs formatted in the Normal style in a Word document are written in a specific font (Times New Roman). The code functions well for this purpose. If the font is as specified, the code prints, "All Normal text contain Times New Roman.", if otherwise the code prints, "Normal text contain unrecognised font(s):", along with the fonts that are not Time New Roman.

My question is whether I can use line number to specify where in the document the unrecognised fonts were found. I understand that python-docx does support line numbers, but I could not find much information (documentation) regarding how to implement the feature in this context.

Any form of help would be appreciated. If there are any questions regarding the code, please ask.

image

code_file.txt

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions