How to delete excel rows in openpyxl?

2019-08-09 19:15发布

I try to delete all rows except first row in existing excel sheets. However it does not delete them I use this function:

rows = [list of tuple data to append sheet]
wb = load_workbook(excelPath)
ws = wb[sheetName]
ws.delete_rows(2, ws.max_row-1)
for row in rows:
    ws.append(row)
wb.save(excelPath)
wb.close()

Whenever call this function, it deletes rows but appends previous last row. I mean If I added 2.-6. rows (including 2 and 6), It writes. Then I want to delete rows and write new values it begins writing from 7.-11. rows

0条回答
登录 后发表回答