hello,

I have word document,
with special words like "$$$Name$$$",
which are replaced with values from a database.

If the special word starts with an underscore, like "$$$_Example$$$",
the text should be replaced by an image.

I use the code below, which works quit well for texts,
but images, just the filename of that image is inserted.
Does anyone has a clue, what I'm doing wrong ?

self.app = win32com.client.Dispatch ( "Word.Application" )
self.app.Visible = visible
self.app.Documents.Open(filename)

"""
Find all occurances of 'find_str' and replace with 'replace_str'
in the active document.
"""
self.app.Selection.HomeKey ( Unit = wdStory )
find = self.app.Selection.Find
find.Text = find_str
while self.app.Selection.Find.Execute():
if find_str.startswith ( '_' ) :
#expression.AddPicture(FileName, LinkToFile, SaveWithDocument, Range)
#self.app.Selection.InlineShapes.AddPicture ( FileName = replace_str )
#self.app.Selection.InlineShapes.AddPicture ( FileName = replace_str, 
LinkToFile = True )
self.app.Selection.TypeParagraph()
self.app.Selection.InlineShapes.AddPicture ( FileName = replace_str, 
SaveWithDocument = True )
#objSelection.InlineShapes.AddPicture(“\\servername\netlogon\signature.jpg”)
self.app.Selection.TypeParagraph()

#LinkToFile:=False
else :
self.app.Selection.TypeText ( Text = replace_str )


thanks,
Stef
_______________________________________________
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32

Reply via email to