问题描述:
Copy其中Sheet中的某一列到另一个Sheet中的某一列. Talk is cheap, here are codes.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
from openpyxl import load_workbook def copy_col_to_other_sheet(file_path='', from_sheet='', from_column_min='', from_column_max='', to_sheet='', to_column=''): wb = load_workbook(file_path) from_ws = wb[from_sheet] to_ws = wb[to_sheet] for row_of_cell_objects in from_ws[from_column_min:from_column_max]: for cell_obj in row_of_cell_objects: to_ws[to_column + cell_obj.coordinate[1:]].value = cell_obj.value wb.save(file_path) copy_col_to_other_sheet('col_copy_tracking.xlsx', 'tracking', 'C2', 'C15', 'control', 'D')
|