-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo.py
More file actions
24 lines (19 loc) · 709 Bytes
/
Copy pathdemo.py
File metadata and controls
24 lines (19 loc) · 709 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from docx import Document
def read_heading_content(docx_path, target_heading):
doc = Document(docx_path)
found_heading = False
content = []
for paragraph in doc.paragraphs:
if paragraph.style.name.startswith('Heading') and paragraph.text == target_heading:
found_heading = True
continue
if found_heading:
if paragraph.style.name.startswith('Heading'):
break
content.append(paragraph.text)
return '\n'.join(content)
# Example usage
docx_file = "your_document.docx"
target_heading = "Your Target Heading"
heading_content = read_heading_content(docx_file, target_heading)
print(heading_content)