This script open all DOCX files in the current folder and print out the bold text from paragraphs and tables.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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