How to delete excel rows in openpyxl?

旧城冷巷雨未停 提交于 2019-12-11 12:44:57

问题


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

来源:https://stackoverflow.com/questions/52144059/how-to-delete-excel-rows-in-openpyxl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!