what is the best way to see what all functions that can be performed using pythoncom module? Specifically, i was working with the win32com module to operate upon excel files. I was not able to find introspection for it as we do for the rest of the modules. Can anyone please suggest how can i retrieve this information?
2 Answers
run the make.py file in \lib\site-packages\win32com\client.
When you run it, a dialog comes up showing installed COM objects... choose the one for the Excel Ojbect library and you'll 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 on Excel, the object you get back will have attributes that support introspection (from the file that gets created when you run the step above). This is basically creating an early-bound version of the COM object.
This topic is covered in detail in Mark Hammond's "Python Programming on Win32". It's an old book, but still very useful! http://www.amazon.com/Python-Programming-WIN32-Windows-Programmers/dp/1565926218
2 Comments
_prop_map_get_ and _prop_map_put_ on the object rather than the usual Pythonic introspection operators.The win32com module doesn't provide the functions to manipulate an Excel spreadsheet directly. Rather, it provides you a function to acquire an Excel spreadsheet object. From this object, you can then manipulate a spreadsheet in an object-oriented fashion:
import win32com.client
excel = win32com.client.Dispatch("Excel.Application")
The methods and properties available to excel can be found in the Application Object documentation, part of the Excel Object Model Reference at MSDN.
For example, the documentation indicates that an Application object has a Workbooks property:
workbooks = excel.Workbooks
The Workbooks collection has an Open method:
workbook = workbooks.Open("C:\\something.xls")
You can now manipulate this workbook using the Workbook documentation!
As you can see, working with win32com follows the MSDN documentation rather closely. :)