I think the following steps will do this work:
- open MS excel.
- read column names in excel file
- write related data based on your data in MySQL.
For step1, may get help from xlrd
For step2, please reference the following code:
# read excel and get appropriate sheet
rb = xlrd.open_workbook(filename, on_demand=True, formatting_info=True)
my_sheet = rb.sheet_by_name(u'template name')
# get column names in item_list
item_list = my_sheet.row_values(1)
nrows = my_sheet.rows
ncolumns = my_sheet.columns
key_index = item_list.index('A')
value_index = item_list.index('B') # of course 'C' and 'D' if needed
For step3, may use index to get value in each row
wb = copy(rb)
ws = wb.get_sheet(i) # get related sheet to write
for row in nrows:
key = my_sheet[row][key_index]
....
Please see my application if needed