Loop through each header cell, and attempt to assign a new value to each cell, pulling the value from column_name_update_map
. If the current header name (header.value
) is not in column_name_update_map
, a KeyError
will be raised that you can safely ignore. In that case, the value is not updated.
for file in os.listdir("C:/Users/yam/Desktop/hhh/python/sterls"):
if file.startswith("TVC"):
wb = load_workbook(file)
if 'Opt-Ins' in wb.sheetnames:
wb.remove(wb['Opt-Ins'])
for ws in wb:
for header in next(ws.rows):
try:
header.value = column_name_update_map[header.value]
except KeyError:
pass
wb.save(file + " (updated headers).xlsx")
* Be the first to Make Comment