Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
# Function to extract information about 'Abstract heading Font Style' from the document
def abstract_heading_font_style(word_file):
doc = Document(word_file)
font_styles = set()

for paragraph in doc.paragraphs:
if any(word in paragraph.text for word in ['Abstract', 'ABSTRACT', 'abstract']):
for run in paragraph.runs:
if any(word in paragraph.text for word in ['Abstract', 'ABSTRACT', 'abstract']) and run.bold:
font_styles.add(run.font.name)

return list(font_styles)

What I have tried:

I have used python docx library for doing this, I have tried multiple times but didn't find any satisfactory solution, plz find any relevant solution, Appreciation in Advance.
Posted
Comments
Richard MacCutchan 22-Mar-24 10:09am    
Have you checked the actual content of the file that you are reading?
Alexander del piero 26-Mar-24 2:53am    
yeah many times....
Richard MacCutchan 22-Mar-24 10:21am    
I just tried that code with a self created document and it correctly found the bold font.
Alexander del piero 26-Mar-24 2:53am    
May be your file formatting is good, but in my case mostly formatting of files are not good according to code, how to fetch correct value when file formatting is not good even ?
Richard MacCutchan 26-Mar-24 4:30am    
Sorry, I cannot answer that. If the code works with a file that I created, then the issue must be with the content of your files. So you need to investigate further. One thing you could try to start with is to run the code in the Python debugger, so you can see the actiual values that are being found in the word file.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900