4

Using win32com.client, how can I count all the number of sheets in a excel file?

vy32
  • 28,461
  • 37
  • 122
  • 246
ichigo
  • 317
  • 2
  • 6
  • 17

1 Answers1

7

Found it:

excel = win32.gencache.EnsureDispatch('Excel.Application')
try:
    wb = excel.Workbooks.Open(file)
except:
    print "Failed to open spreadsheet " + file
    sys.exit(1)
count = wb.Sheets.Count
ichigo
  • 317
  • 2
  • 6
  • 17