We have an excel file with the same column names of another excel file but in a shuffled way:
excel_1_columns = ["name", "address", "phone"]
and
excel_2_columns = ["address", "name", "phone"]
We want to arrange excel 2 the same way excel 1 is.
Actually these names are just for the purpose of making you understand but it can contain hundreds of columns.
excel_1_columns and excel_2_columns always have the same length but not the same order.
We want to use openpyxl to arrange both to look the same.
We had the idea of converting to data frames and then save into an excel, but we don't want to lose the formatting and the theme used with the original excels.
I started with getting columns names from excel 1:
excel_1_columns = []
for row in intro_sheet.iter_rows(min_row=1, max_row=1):
for cell in row:
excel_1_columns.append(cell.value)
My logic is to loop over excel_1_columns and append a new column into excel 2:
for col in col_order:
excel_2.insert_cols(idx = 1)
# rename
excel_2.cell(row = 1, column = 1).value = str(col)
and then we work within excel 2 and move cell values from old columns into the new appended ones and delete the old ones.
How can we move cell values from column named old_phone for example to phone column that was appended in the for loop?