Introspection of win32com / pythoncom module

What is the best way to see that all the functions that can be performed using the pythoncom module? In particular, I worked with the win32com module to work with excel files. I could not find an introspection for him, as well as for the rest of the modules. Can anyone suggest how I can get this information?

+6
python
source share
2 answers

run the make.py file in \ lib \ site-packages \ win32com \ client.

When you run it, a dialog box appears showing the installed COM objects ... select the one used for the Excel Ojbect library and you will get something like this:

c:\Python26\Lib\site-packages\win32com\client>makepy.py Generating to C:\Python26\lib\site-packages\win32com\gen_py\00020813-0000-0000-C 000-000000000046x9x1x0.py Building definitions from type library... Generating... Importing module 

Now, when you call win32com.client.Dispatch in Excel, the returned object will have attributes that support introspection (from the file that is created during the above step). This basically creates an earlier version of the COM object.

This section is covered in detail in Mark Hammond's "Win32 Python Programming Program." This is an old book, but still very useful! http://www.amazon.com/Python-Programming-WIN32-Windows-Programmers/dp/1565926218

+4
source share

The win32com module win32com not provide functions for directly managing an Excel spreadsheet. Rather, it provides you with a function to get an Excel spreadsheet object. From this object, you can then manipulate the spreadsheet in an object-oriented way:

 import win32com.client excel = win32com.client.Dispatch("Excel.Application") 

The methods and properties available for excel can be found in the Application Object documentation, which is part of the Excel Object Model Reference on MSDN.

For example, the documentation indicates that the Application object has the Workbooks property:

 workbooks = excel.Workbooks 

Workbooks collection has an Open method:

 workbook = workbooks.Open("C:\\something.xls") 

Now you can manipulate this book using the Workbook documentation !

As you can see, working with win32com is pretty closely related to the MSDN documentation. :)

+2
source share

All Articles