How to swap columns using openpyxl
问题 I've .xlsx file. Rows are good, values are just fine. But i need to change the columns order by list of new columns positions, e.g: old = [1, 2, 3, 4] new = [2, 1, 4, 3] Docs are checked - there is no straightforward options for this problem. I've tried to iterate over columns, so: old = {cell.column: cell.value for cell in ws[1]}.keys() # [1, 2, 3, 4] new = [2, 1, 4, 3] for i, col in enumerate(ws.iter_cols(max_col=old[-1]), 1): if old[i-1] != new[i-1]: for one in ws[get_column_letter(i)]: