How to delete lines in openpyxl with conditions?

Asked

Viewed 32 times

-1

I’m trying to delete lines that have data repeated this way:

nome = sheet['I2'].value
for coluna in sheet.iter_cols(min_col=9, max_col=9, min_row=3):
    for celula in coluna:
        if celula.value == nome:
            sheet.delete_rows(celula,1)
        else:
            nome = celula.value

Gives the following error:

Typeerror: int() argument must be a string, a bytes-like Object or a number, not 'Cell'

Someone knows a solution?

1 answer

-1

I also had this question and checked in the openpyxls documentation that delete_rows needs the line index, ie the line number and how many lines you need to delete. You can access the line number in Cell’s Row property.

sheet.delete_rows(celula.row,1)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.