Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Anirudh Palaparthi committed Sep 7, 2021
2 parents 08acb69 + 4081df5 commit 0f54e25
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 12 additions & 4 deletions pyostie/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,13 @@ def extract_docx(self):

class XLSXParser:

def __init__(self, filename):
def __init__(self, filename, sheet_name=None):
"""
:param filename:
"""
self.file = filename
self.sheet = sheet_name

def extract_xlsx(self):
"""
Expand All @@ -53,12 +54,19 @@ def extract_xlsx(self):
"""
out_list = []
book = xlrd.open_workbook(self.file)
for val in range(len(book.sheet_names())):
sheet = book.sheet_by_index(val)
if self.sheet is None:
for val in range(len(book.sheet_names())):
sheet = book.sheet_by_index(val)
for res in range(sheet.nrows):
output = " " + " ".join(str(val_) for val_ in (sheet.row_values(res)))
out_list.append(output)
return out_list
elif self.sheet is not None:
sheet = book.sheet_by_name(self.sheet)
for res in range(sheet.nrows):
output = " " + " ".join(str(val_) for val_ in (sheet.row_values(res)))
out_list.append(output)
return out_list
return out_list


class CSVParser:
Expand Down

0 comments on commit 0f54e25

Please sign in to comment.