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"
worddoc.Content.Text=" I am a text!"
worddoc.Content.MoveEnd
worddoc.Close() # Close the Word Document (a save-Dialog pops up)
wordapp.Quit() # Close the Word Application


The word doc from the above code will only contain " I am a text!" I would like to know how i can add/append text onto a word doc so that i have both "Hello" and " I am a text!" in the word doc.

Plz help me.......

Hi,

I'm not going to install this module but I have a hunch: what if you do:

worddoc.Content.Text = "Hello"
worddoc.Content.Text +=" I am a text!"

instead of your lines. Maybe the Text attribute is only evaluated at the end of the rest of manipulations, before closing the app. If I'm right, then You overwrite the "Hello" with "I am a text!".

Another solution is simply to make one big string elsewhere and pass it to text:

worddoc.Content.Text = my_string_built_elsewhere