问题描述:
需要把excel中的某一列做转换大小写操作,具体代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
from openpyxl import load_workbook def change_col_to_upper_or_lower(file_path='', sheet='', column='', to_upper=True, ): wb = load_workbook(file_path) ws = wb[sheet] max_row = ws.max_row min_row = ws.min_row for row_of_cell_objects in ws[column + str(min_row):column + str(max_row)]: for cell_obj in row_of_cell_objects: if to_upper: cell_obj.value = cell_obj.value.upper() else: cell_obj.value = cell_obj.value.lower() wb.save(file_path) change_col_to_upper_or_lower('col_copy_tracking.xlsx','control','I')
|