You are on page 1of 1

import openpyxl

def delete_matched_items(file_path, sheet_name, column, value):


# Load the workbook
wb = openpyxl.load_workbook(file_path)

# Get the sheet


sheet = wb[sheet_name]

# Get the column index


column_index = None
for i, cell in enumerate(sheet[1]):
if cell.value == column:
column_index = i
break

# Iterate over the rows and delete the matched items


i = 2
while i <= sheet.max_row:
cell = sheet.cell(row=i, column=column_index+1)
if cell.value == value:
sheet.delete_rows(i, 1)
else:
i += 1

# Save the workbook


wb.save(file_path)

list=[$ListItem3$]

for x in list
for l in file
delete_matched_items('file[l]', 'Sheet1', 'Column Name', 'list[x]')

You might also like