Python中是否有方法比较不同行中的Excel单元格?

2024-03-29 12:53:09 发布

您现在位置:Python中文网/ 问答频道 /正文

Python中是否有方法比较不同行中的Excel单元格,如果单元格不同,则插入一行? 以下是迄今为止我对python代码的了解:

filename2 = "myfile.xlsx."
wb2 = xl.load_workbook(filename2)
ws2 = wb2.active

mr2 = ws2.max_row

#here is where I compare the cells and insert a row if it does not match

for i in range(2, mr + 1):
    if ws2.cell(row=i, column=2).value != ws2.cell(row=i + 1, column=2).value:
        ws2.insert_rows(idx= i + 1)

wb2.save(str(filename2))