简体   繁体   中英

Deleting first 3 rows in Excel with python

I want to delete the first 3 rows from a specific sheet in Excel with Python (openpyxl).

excel_file = xl.load_workbook('Test.xlsm')
excel_sheet = excel_file('Data')
excel_sheet.delete_rows(idx=0, amount=3)
excel_file.save('Test.xlsm')

But this is not working as expected.

I am getting a long error which ends with:

"for idx, c in enumerate(coordinate):
  TypeError: 'NoneType' object is not iterable"

What does this mean?

Why are the first 3 rows are not deleted?

Try setting the sheet name using square brackets and the first row is row 1 not row 0

excel_sheet = excel_file['Data']
excel_sheet.delete_rows(idx=1, amount=3)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM