I’m working on code to delete columns in an Excel sheet, and I’m trying to figure out why columns are not being deleted from my delete_cols
function call with openpyxl
. Here is the snippet of code I have to do that:
i=4
for column in sheet.iter_cols(min_col=5):
i+=1
name=column[0].value
if name not in names_of_employees:
sheet.delete_cols(i, amount=1)
There’s a chance I’m misunderstanding the delete_cols
function, so feel free to tell me if that’s the case. I did double-check the column contents as well as the worksheet I’m trying to delete from, and those both seem to be correct. Would you guys happen to know why this is happening?