在 Openpyxl 中查找重复行的索引

Find index of duplicate rows in Openpyxl

我想在 excel 文件中找到所有重复行的索引,并将它们添加到稍后处理的列表中。

unwantedRows = []
Row = []
item = ""

for index, row in enumerate(ws1.iter_rows(max_col = 50), start = 1):
  for cell in row:
    if cell.value:
      item += cell.value
  if item in Row:
    unwantedRows.append(index)
  else:
    Row.append(item)

但是这不起作用。它只索引完全空的行。我该如何解决?

unwantedRows = []
Rows = []

for index, row in enumerate(ws1.iter_rows(max_col = 50), start = 1):
  sublist = []
  for cell in row:
    sublist.append(cell.value)

  if sublist not in Rows:
    Rows.append((sublist))
  else:
    unwantedRows.append(index)

没有元组:

row_numbers_to_delete = []
rows_to_keep = []
for row in ws.rows:
    working_list = []
    for cell in row:
        working_list.append(cell.value)
    if working_list not in rows_to_keep:
        rows_to_keep.append(working_list)
    else:
        row_numbers_to_delete.append(cell.row)
for row in row_numbers_to_delete:
    ws.delete_rows(
        idx=row,
        amount=1
    )