-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdoctodocs.py
More file actions
33 lines (23 loc) · 856 Bytes
/
Copy pathdoctodocs.py
File metadata and controls
33 lines (23 loc) · 856 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
25
26
27
28
29
30
31
32
33
# from docx import Document
# def convert_doc_to_docx(doc_file, docx_file):
# # Open the .doc file
# with open(doc_file, 'rb') as doc:
# docx = Document(doc)
# # Save as .docx file
# docx.save(docx_file)
# # Provide the paths of the input .doc file and the output .docx file
# input_doc_file = 'input.doc'
# output_docx_file = 'output.docx'
# convert_doc_to_docx(input_doc_file, output_docx_file)
from docx import Document
def extract_table_headings(docx_file_path, table_index=0):
doc = Document(docx_file_path)
table = doc.tables[table_index]
headings = []
for cell in table.rows[0].cells:
headings.append(cell.text.strip())
return headings
# Example usage:
docx_file_path = "your_document.docx"
headings = extract_table_headings(docx_file_path)
print("Table Headings:", headings)