How to delete a worksheet

2,350 views
Skip to first unread message

PG

unread,
Jun 10, 2009, 2:42:40 PM6/10/09
to python-excel
I am newbie to python. I need to check whether worksheet exist or not
in an excel. If exist, I need to delete. Please help me or share the
code snippet if you have?

I did checked xlrd, xlwt, win32com, and pyexcelerator. All I could do
is add a worksheet. But I didn't find a way to delete.

thanks
-PG

John Machin

unread,
Jun 10, 2009, 6:54:55 PM6/10/09
to python...@googlegroups.com

Hi PG, you should be able to do it using win32com.

From the Excel 2003 VBA help:
"""
This example deletes Sheet3 in the active workbook without displaying
the confirmation dialog box.

Application.DisplayAlerts = False
Worksheets("Sheet3").Delete
Application.DisplayAlerts = True
"""

The operative line will after translation from VB to Python look
something like:
your_handle.Worksheets("Sheet3").Delete()

HTH,
John

Reply all
Reply to author
Forward
0 new messages