Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
This script open all DOCX files in the current folder and print out the bold text from paragraphs and tables.
"""
This script open all DOCX files in the current folder and print out the bold text from paragraphs and tables.
"""
import docx
import glob
def print_bold_text_in_paragraphs(paragraphs):
for p in paragraphs:
for run in p.runs:
if run.bold:
print(run.text)
files = glob.glob("*.docx")
for file in files:
print(f"Printing all bold text from {file}:")
doc = docx.Document(file)
print_bold_text_in_paragraphs(doc.paragraphs)
# Iterate all cells in all tables
for table in doc.tables:
for row in table.rows:
for cell in row.cells:
print_bold_text_in_paragraphs(cell.paragraphs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment