Skip to content

Commit 76627f4

Browse files
committed
Release 1.2.2 support auto add columns
1 parent 69bc20b commit 76627f4

File tree

3 files changed

+37
-4
lines changed

3 files changed

+37
-4
lines changed

ExcelDataDriver/ExcelParser/ABCParserStrategy.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,44 @@ def map_data_row_into_test_data_obj(self, ws_column_indexes, ws_title, row_index
3535
def get_all_worksheet(self, wb):
3636
return list(wb)
3737

38+
def parsing_major_column_indexs(self, ws):
39+
ws_column_indexs = {}
40+
key_index_row = 0
41+
found_default_column_indexs = False
42+
43+
# Parse mandatory property
44+
for index, row in enumerate(ws.rows):
45+
if index > self.maximum_column_index_row:
46+
break
47+
for cell in row:
48+
if (cell.value is not None) and (cell.value in self.DEFAULT_COLUMN_INDEXS):
49+
ws_column_indexs[cell.value] = column_index_from_string(coordinate_from_string(cell.coordinate)[0])
50+
print(str(datetime.now()) + ': Mandatory : ' + str(cell.value) + ' : ' + str(
51+
cell.coordinate) + ' : ' + str(
52+
column_index_from_string(coordinate_from_string(cell.coordinate)[0])))
53+
key_index_row = index + 1
54+
found_default_column_indexs = True
55+
56+
if (cell.value is not None) and (cell.value not in self.DEFAULT_COLUMN_INDEXS) and (found_default_column_indexs is False):
57+
field_name = str(cell.value).lower().strip().replace(" ", "_")
58+
if field_name == self.main_column_key:
59+
key_index_row = index + 1
60+
61+
if len(ws_column_indexs) > 0:
62+
break
63+
64+
return ws_column_indexs, key_index_row
65+
3866
def parsing_column_indexs(self, ws):
3967
ws_column_indexs = {}
68+
4069
# Parse mandatory property
4170
for index, row in enumerate(ws.rows):
4271
if index > self.maximum_column_index_row:
4372
break
4473
for cell in row:
4574
if (cell.value is not None) and (cell.value in self.DEFAULT_COLUMN_INDEXS):
75+
found_mandatory_property = True
4676
ws_column_indexs[cell.value] = column_index_from_string(coordinate_from_string(cell.coordinate)[0])
4777
print(str(datetime.now())+': Mandatory : '+str(cell.value) + ' : ' + str(cell.coordinate) + ' : ' + str(column_index_from_string(coordinate_from_string(cell.coordinate)[0])))
4878
self.start_row = index + 1

ExcelDataDriver/ExcelParser/ParserContext.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,13 @@ def parse(self, wb):
2828
return ws_test_data_rows
2929

3030
def insert_extra_columns(self, wb, columns):
31-
for ws in self.parser_strategy.get_all_worksheet(wb):
32-
ws_column_indexs = self.parser_strategy.parsing_column_indexs(ws)
31+
ws_list = self.parser_strategy.get_all_worksheet(wb)
32+
for ws in ws_list:
33+
print(str(datetime.now()) + ': start parse data...')
34+
ws_column_indexs, key_index_row = self.parser_strategy.parsing_major_column_indexs(ws)
3335
for column in reversed(columns):
3436
if column in ws_column_indexs:
3537
continue
3638
ws.insert_cols(1)
37-
ws['A' + str(self.parser_strategy.start_row - 2)] = column
39+
ws['A' + str(key_index_row)] = column
40+
print(str(datetime.now()) + ': Done parse data...')

ExcelDataDriver/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
from ExcelDataDriver.Config.CaptureScreenShotOption import CaptureScreenShotOption
4141

4242

43-
__version__ = '1.2.1'
43+
__version__ = '1.2.2'
4444

4545

4646
class ExcelDataDriver:

0 commit comments

Comments
 (0)