Skip to content

Commit

Permalink
Release 1.2.2 support auto add columns
Browse files Browse the repository at this point in the history
  • Loading branch information
atthaboon committed Nov 23, 2020
1 parent 69bc20b commit 76627f4
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
30 changes: 30 additions & 0 deletions ExcelDataDriver/ExcelParser/ABCParserStrategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,44 @@ def map_data_row_into_test_data_obj(self, ws_column_indexes, ws_title, row_index
def get_all_worksheet(self, wb):
return list(wb)

def parsing_major_column_indexs(self, ws):
ws_column_indexs = {}
key_index_row = 0
found_default_column_indexs = False

# Parse mandatory property
for index, row in enumerate(ws.rows):
if index > self.maximum_column_index_row:
break
for cell in row:
if (cell.value is not None) and (cell.value in self.DEFAULT_COLUMN_INDEXS):
ws_column_indexs[cell.value] = column_index_from_string(coordinate_from_string(cell.coordinate)[0])
print(str(datetime.now()) + ': Mandatory : ' + str(cell.value) + ' : ' + str(
cell.coordinate) + ' : ' + str(
column_index_from_string(coordinate_from_string(cell.coordinate)[0])))
key_index_row = index + 1
found_default_column_indexs = True

if (cell.value is not None) and (cell.value not in self.DEFAULT_COLUMN_INDEXS) and (found_default_column_indexs is False):
field_name = str(cell.value).lower().strip().replace(" ", "_")
if field_name == self.main_column_key:
key_index_row = index + 1

if len(ws_column_indexs) > 0:
break

return ws_column_indexs, key_index_row

def parsing_column_indexs(self, ws):
ws_column_indexs = {}

# Parse mandatory property
for index, row in enumerate(ws.rows):
if index > self.maximum_column_index_row:
break
for cell in row:
if (cell.value is not None) and (cell.value in self.DEFAULT_COLUMN_INDEXS):
found_mandatory_property = True
ws_column_indexs[cell.value] = column_index_from_string(coordinate_from_string(cell.coordinate)[0])
print(str(datetime.now())+': Mandatory : '+str(cell.value) + ' : ' + str(cell.coordinate) + ' : ' + str(column_index_from_string(coordinate_from_string(cell.coordinate)[0])))
self.start_row = index + 1
Expand Down
9 changes: 6 additions & 3 deletions ExcelDataDriver/ExcelParser/ParserContext.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,13 @@ def parse(self, wb):
return ws_test_data_rows

def insert_extra_columns(self, wb, columns):
for ws in self.parser_strategy.get_all_worksheet(wb):
ws_column_indexs = self.parser_strategy.parsing_column_indexs(ws)
ws_list = self.parser_strategy.get_all_worksheet(wb)
for ws in ws_list:
print(str(datetime.now()) + ': start parse data...')
ws_column_indexs, key_index_row = self.parser_strategy.parsing_major_column_indexs(ws)
for column in reversed(columns):
if column in ws_column_indexs:
continue
ws.insert_cols(1)
ws['A' + str(self.parser_strategy.start_row - 2)] = column
ws['A' + str(key_index_row)] = column
print(str(datetime.now()) + ': Done parse data...')
2 changes: 1 addition & 1 deletion ExcelDataDriver/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
from ExcelDataDriver.Config.CaptureScreenShotOption import CaptureScreenShotOption


__version__ = '1.2.1'
__version__ = '1.2.2'


class ExcelDataDriver:
Expand Down

0 comments on commit 76627f4

Please sign in to comment.