Entry
How can a automate Windows Applications with Python and COM ?
Jul 1st, 2008 11:35
sheana krat, Mustafa Görmezer, Mustafa Görmezer, http://www.win32com.de
With the win32com package included in the Python Windows extensions
(Pywin32) from Mark Hammond one can automate every Windows applications
which exposes Microsoft COM Type Libraries.
For example all Microsoft Office Applications (Word, Excel, Powerpoint,
Outlook, Project, ...) can be automated with the win32com package.
Here is a small example which opens a Word document with Microsoft
Office and types some text into the document:
import win32com.client
wordapp = win32com.client.Dispatch("Word.Application") # Create new Word
Object
wordapp.Visible = 0 # Word Application should`t be visible
worddoc = wordapp.Documents.Add() # Create new Document Object
worddoc.PageSetup.Orientation = 1 # Make some Setup to the Document:
worddoc.PageSetup.LeftMargin = 20
worddoc.PageSetup.TopMargin = 20
worddoc.PageSetup.BottomMargin = 20
worddoc.PageSetup.RightMargin = 20
worddoc.Content.Font.Size = 11
worddoc.Content.Paragraphs.TabStops.Add (100)
worddoc.Content.Text = "Hello, I am a text!"
worddoc.Content.MoveEnd
worddoc.Close() # Close the Word Document (a save-Dialog pops up)
wordapp.Quit() # Close the Word Application
More examples can be found at the Python/Pywin32 Script Collection at
http://win32com.goermezer.de
http://www.indianhandicraftsexporters.com
http://www.topgiftsideas.com
http://www.eindianweddingcards.com