How to delete an existing worksheet in excel file using xlutils, xlwt, xlrd with python

JinFy picture JinFy · Apr 10, 2012 · Viewed 9.9k times · Source

I tried to search many places but dit not see any example snippet of code about how to delete an existing worksheet in excel file by using xlutils or xlwt with python. Who can help me, please?

Answer

David Merritt picture David Merritt · Jul 17, 2012

I just dealt with this and although this is not generally a good coding choice, you can use the internal Workbook_worksheets to access and set the worksheets for a workbook object.

write_book._Workbook__worksheets = [write_book._Workbook__worksheets[0]]

this would strip everything but the first worksheet associated with a Workbook