8

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 2

5

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

Sign up to request clarification or add additional context in comments.

2 Comments

Not sure if I'm doing it wrong but the introspection seems to involve looking inside _prop_map_get_ and _prop_map_put_ on the object rather than the usual Pythonic introspection operators.
Thanks for the tip, I had some great hope about this. However I cannot seem to find installed application (Inventor and FeatureCAM from Autodesk). Any ideas why they might be missing ? I can access them with win32com.client.Dispatch
2

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. :)

2 Comments

This looks copied straight off from Python win32 book by Mark Hammond.
@GTM: Oh? I wish I knew that there was book about win32 in Python when I learned this! :) I can assure you, I didn't copy this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.