-
Notifications
You must be signed in to change notification settings - Fork 0
/
DOCText.py
29 lines (25 loc) · 1007 Bytes
/
DOCText.py
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
from docx import Document
class DocxToTextConverter:
def __init__(self, docx_file_path):
self.docx_file_path = docx_file_path
self.text_content = self.read_text_from_docx()
self.text_file_path = self.text_file_path()
def read_text_from_docx(self):
doc = Document(self.docx_file_path)
text = ""
count = 0
for paragraph in doc.paragraphs:
if len(paragraph.text) > 0:
count += 1
if count == 1:
text += paragraph.text + "\n"
else:
text += f"{count-1}."+paragraph.text + "\n"
return text
def create_text_file(self, text_file_path="Questions.txt"):
with open(text_file_path, "w") as file:
file.write(self.text_content)
return "{text_file_path} created successfully".format(text_file_path=text_file_path)
def text_file_path(self):
self.text_file_path
return self.text_file_path