Reputation:
i want to read heading from a docx file but Document module does not have property of read heading how i can do that
from docx import Document
def docheading():
document = Document('C://Users//yousafzai//Desktop//Database//riya//riya//AbdulMateen.docx')
headings=document.heading
Upvotes: 1
Views: 2451
Reputation: 131
This is how you can extract the title:
for paragraph in document.paragraphs:
if paragraph.style.name=='Title':
doc_title = paragraph.text
Upvotes: 1
Reputation: 23
I kinda did the same thing. I did something like this the attribute you are looking for is Style.name
for paragraph in paragraphs:
if paragraph.style.name=='Heading 1':
print (paragraph.text)
Upvotes: 2
Reputation: 1749
Try a different library, for example paradocx, which can read paradata from the Office XML spec using something like style='Heading 1'
Upvotes: 0