pywin32 excelfind工作簿中有多less张和数字索引?

如何在pywin32的工作簿中find工作表的数量?

另外,是否有任何文档如何使用Excel中的pywin32? 我似乎甚至找不到代码示例或任何东西。

 from win32com.client import Dispatch xl= Dispatch("Excel.Application") xl.Visible = True # otherwise excel is hidden # newest excel does not accept forward slash in path wb = xl.Workbooks.Open(r'U:\Example.xls') print "count of sheets:", wb.Sheets.Count for sh in wb.Sheets: print sh.Name wb.Close() xl.Quit() 

结果:

 count of sheets: 3 Sheet1 Sheet2 Sheet3 

Excel中提供了最好的文档。 一般来说,我logging一个macros,看看生成的代码,从帮助文件中学习,然后用Python编写我需要的东西。