Introspection Of Win32com Module / Pythoncom Module
Solution 1:
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
Solution 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.clientexcel= 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. :)
Post a Comment for "Introspection Of Win32com Module / Pythoncom Module"