Loading pyehub/excel_to_request_format.py +8 −13 Original line number Diff line number Diff line Loading @@ -70,27 +70,22 @@ class Converter: """ self._excel_file = excel_file # function to return the file extension file_extension = pathlib.Path(excel_file).suffix if file_extension == '.xls': self._kind = 'xls' elif file_extension == '.xlsx': self._kind = 'xlsx' else: self._file_extension = pathlib.Path(excel_file).suffix if self._file_extension not in [".xls", ".xlsx"]: raise FormatUnsupportedError(f'File must be of format ".xls" or ".xlsx".') if self._kind=='xls': if self._file_extension=='.xls': self._file = xlrd.open_workbook(excel_file) else: self._file = openpyxl.load_workbook(excel_file) def _get_columns(self, sheet_name, start=0): if self._kind=='xls': if self._file_extension=='.xls': sheet = self._file.sheet_by_name(sheet_name) # xlrd style for colx in range(start, sheet.ncols): yield sheet.col_values(colx)[1:] # ipysheet didn't allow editable column names, # so added an index row to sheets and slicing it off here elif self._kind=='xlsx': else: sheet = self._file[sheet_name] # openpyxl style for i,colx in enumerate(sheet.columns): # Different writing with openpyxl if i<start: continue; # Skip until start line is reached (generator can't skip earlier) Loading Loading @@ -159,13 +154,13 @@ class _NewFormatConverter(Converter): return super()._get_columns(sheet_name, start=start) def _get_general(self): if self._kind == 'xls': # xlrd stype if self._file_extension=='.xls': # xlrd stype sheet = self._file.sheet_by_name('General') return { 'interest_rate': float(sheet.cell(2,1).value), # cell(2, 1) in xlrd as skip 1st row and col } elif self._kind == 'xlsx': # openpyxl style else: # openpyxl style sheet = self._file['General'] return { Loading pyehub/network_to_request_format.py +7 −12 Original line number Diff line number Diff line Loading @@ -22,27 +22,22 @@ class Converter: def __init__(self, excel_file): self._excel_file = excel_file # function to return the file extension file_extension = pathlib.Path(excel_file).suffix if file_extension == '.xls': self._kind = 'xls' elif file_extension == '.xlsx': self._kind = 'xlsx' else: self._file_extension = pathlib.Path(excel_file).suffix if self._file_extension not in [".xls", ".xlsx"]: raise FormatUnsupportedError(f'File must be of format ".xls" or ".xlsx".') if self._kind=='xls': if self._file_extension=='.xls': self._file = xlrd.open_workbook(excel_file) else: self._file = openpyxl.load_workbook(excel_file) def _get_columns(self, sheet_name, start=0): if self._kind=='xls': if self._file_extension=='.xls': sheet = self._file.sheet_by_name(sheet_name) # xlrd style for colx in range(start, sheet.ncols): yield sheet.col_values(colx)[1:] # ipysheet didn't allow editable column names, # so added an index row to sheets and slicing it off here elif self._kind=='xlsx': else: sheet = self._file[sheet_name] # openpyxl style for i,colx in enumerate(sheet.columns): # Different writing with openpyxl if i<start: continue; # Skip until start line is reached (generator can't skip earlier) Loading Loading @@ -155,7 +150,7 @@ class NewFormatConverter(Converter): return links def _get_network(self): if self._kind=='xls': if self._file_extension=='.xls': sheet = self._file.sheet_by_name('Network') # xlrd style return{ 'fixed_network_investment_cost': float(sheet.cell(1, 1).value), Loading Loading
pyehub/excel_to_request_format.py +8 −13 Original line number Diff line number Diff line Loading @@ -70,27 +70,22 @@ class Converter: """ self._excel_file = excel_file # function to return the file extension file_extension = pathlib.Path(excel_file).suffix if file_extension == '.xls': self._kind = 'xls' elif file_extension == '.xlsx': self._kind = 'xlsx' else: self._file_extension = pathlib.Path(excel_file).suffix if self._file_extension not in [".xls", ".xlsx"]: raise FormatUnsupportedError(f'File must be of format ".xls" or ".xlsx".') if self._kind=='xls': if self._file_extension=='.xls': self._file = xlrd.open_workbook(excel_file) else: self._file = openpyxl.load_workbook(excel_file) def _get_columns(self, sheet_name, start=0): if self._kind=='xls': if self._file_extension=='.xls': sheet = self._file.sheet_by_name(sheet_name) # xlrd style for colx in range(start, sheet.ncols): yield sheet.col_values(colx)[1:] # ipysheet didn't allow editable column names, # so added an index row to sheets and slicing it off here elif self._kind=='xlsx': else: sheet = self._file[sheet_name] # openpyxl style for i,colx in enumerate(sheet.columns): # Different writing with openpyxl if i<start: continue; # Skip until start line is reached (generator can't skip earlier) Loading Loading @@ -159,13 +154,13 @@ class _NewFormatConverter(Converter): return super()._get_columns(sheet_name, start=start) def _get_general(self): if self._kind == 'xls': # xlrd stype if self._file_extension=='.xls': # xlrd stype sheet = self._file.sheet_by_name('General') return { 'interest_rate': float(sheet.cell(2,1).value), # cell(2, 1) in xlrd as skip 1st row and col } elif self._kind == 'xlsx': # openpyxl style else: # openpyxl style sheet = self._file['General'] return { Loading
pyehub/network_to_request_format.py +7 −12 Original line number Diff line number Diff line Loading @@ -22,27 +22,22 @@ class Converter: def __init__(self, excel_file): self._excel_file = excel_file # function to return the file extension file_extension = pathlib.Path(excel_file).suffix if file_extension == '.xls': self._kind = 'xls' elif file_extension == '.xlsx': self._kind = 'xlsx' else: self._file_extension = pathlib.Path(excel_file).suffix if self._file_extension not in [".xls", ".xlsx"]: raise FormatUnsupportedError(f'File must be of format ".xls" or ".xlsx".') if self._kind=='xls': if self._file_extension=='.xls': self._file = xlrd.open_workbook(excel_file) else: self._file = openpyxl.load_workbook(excel_file) def _get_columns(self, sheet_name, start=0): if self._kind=='xls': if self._file_extension=='.xls': sheet = self._file.sheet_by_name(sheet_name) # xlrd style for colx in range(start, sheet.ncols): yield sheet.col_values(colx)[1:] # ipysheet didn't allow editable column names, # so added an index row to sheets and slicing it off here elif self._kind=='xlsx': else: sheet = self._file[sheet_name] # openpyxl style for i,colx in enumerate(sheet.columns): # Different writing with openpyxl if i<start: continue; # Skip until start line is reached (generator can't skip earlier) Loading Loading @@ -155,7 +150,7 @@ class NewFormatConverter(Converter): return links def _get_network(self): if self._kind=='xls': if self._file_extension=='.xls': sheet = self._file.sheet_by_name('Network') # xlrd style return{ 'fixed_network_investment_cost': float(sheet.cell(1, 1).value), Loading