![]() |
Reading/Writing Word Documents in Python (with win32com.client?)
I have a MS Word document that I am using as a template. After a test is run, certain parts of the Word document need to be replaced with the test results. For example, there is a section in the Word document that looks similar to:
:
Test NameDoes anyone know what the best way to modify a Word document in Python is? I have installed the Win32 Extensions for Python, but it is very difficult to figure out how to use. So far the best reference I have found is Automating Word Using the Word Object Model MSDN reference, which helps a little, but the code is in VB/C# and I don't know where some of the objects come from; eg: :
object replaceAll = Word.WdReplace.wdReplaceAll;I read somewhere using Word Macros may be easier. Is this true? If so, how would I go about writing/running a Macro from Python? Or is there another, easier way to do this? Here's what I have so far: :
import win32com.client |
Thanks for all your help :rolleyes:
I finally figured it out myself, thanks mostly to this example. :
import os |
This function is similar to the last one but instead of replacing only the first instance of the word, it replaces all instances of the word. It uses the extended Find.Execute method (11 arguments in all!) instead.
:
wdFindContinue = 1 |
| All times are GMT -5. The time now is 12:18 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC