Skip to content

Instantly share code, notes, and snippets.

@makzan
Created November 17, 2021 06:50
Show Gist options
  • Save makzan/4fb414934f2ddb8c17e81a3c5737ac35 to your computer and use it in GitHub Desktop.
Save makzan/4fb414934f2ddb8c17e81a3c5737ac35 to your computer and use it in GitHub Desktop.
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