EnglishFrenchGermanItalianPortugueseRussianSpanish
Home arrow Script Collection arrow Create and write Text to a Word Document
Create and write Text to a Word Document PDF Print E-mail
 
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



Comments (2)
RSS comments
1. 20-08-2008 15:27
 
MSDN Documentation
OK, you`re right. 
 
Here is the Link MSDN to the Object Model documentation of Microsoft Word 2007: http://msdn.microsoft.com/en-us/library/bb244515.aspx
Guest
 
admin
2. 18-08-2005 11:08
 
Documentation
I'm trying to find some comprehensive documentation for all the API's word exposes thru COM to python. 
 
I've looked on your site and MSDN, i'm surprised you don't have it on your site to be honest.  
 
Any help would be nice.
Guest
 
Guest

Write Comment
  • Please keep the topic of messages relevant to the subject of the article.
  • Personal verbal attacks will be deleted.
  • Please don't use comments to plug your web site. Such material will be removed.
  • Just ensure to *Refresh* your browser for a new security code to be displayed prior to clicking on the 'Send' button.
  • Keep in mind that the above process only applies if you simply entered the wrong security code.
Name:
E-mail
Comment:

Code:* Code
I wish to be contacted by email regarding additional comments

Last Updated ( Thursday, 02 February 2006 )
 
< Prev   Next >

Post your scripts

If you have interesting scripts to share with the community, please post them to this site. Hint: For syntax highlighting and correct Python intendation place your code between html tags <pre> and </pre>.

Suggested

RSS category feeds

RSS site feeds

My prefered Python IDE

My prefered Python editor is Pyscripter from MMExperts. It is not only an editor. Pyscripter is a full Python IDE including (remote) debugging, a class browser, and all other nice helpers which a full featured IDE needs.

Do you have a script for me ?

Do you have an interesting Python script which does some really cool thing on Windows ? Please post them to this site. It`s very simple - simply copy&paste it to this form. No login is requiered.

Hint: For syntax highlighting and correct Python intendation place your code between html tags <pre> and </pre>.

My prefered web framework

My prefered web framework for developing web applications is Django. Django calls itself The web framework for perfectionists with deadlines. It is a really fast, scalable and (thanks Python) the sexiest web framework of the world.