John Salerno wrote:
I figured my first step is to install the win32 extension, which I did,
but I can't seem to find any documentation for it. A couple of the links
on Mark Hammond's site don't seem to work.
Anyway, all I need to do is search in the Word document for certain
strings and either delete them or replace them. Easy enough, if only I
knew which function, etc. to use.
Hope someone can push me in the right direction.
Thanks.
The easiest way for me to do things like this is to do it in Word and
record a VB Macro. For instance you will see something like this:
Selection.Find. ClearFormatting
Selection.Find. Replacement.Cle arFormatting
With Selection.Find
.Text = "save it"
.Replacement.Te xt = "dont save it"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchByte = False
.CorrectHangulE ndings = False
.MatchAllWordFo rms = False
.MatchSoundsLik e = False
.MatchWildcards = False
.MatchFuzzy = False
End With
Selection.Find. Execute Replace:=wdRepl aceAll
and then hand translate it to Win32 Python, like:
wordApp = Dispatch("Word. Application")
wordDoc=wordApp .Documents.Add( ...some word file name...)
wordRange=wordD oc.Range(0,0).S elect()
sel=wordApp.Sel ection
sel.Find.ClearF ormatting()
sel.Find.Replac ement.ClearForm atting()
sel.Find.Text = "save it"
sel.Find.Replac ement.Text = "dont save it"
sel.Find.Forwar d = True
sel.Find.Wrap = constants.wdFin dContinue
sel.Find.Format = False
sel.Find.MatchC ase = False
sel.Find.MatchW holeWord = False
sel.Find.MatchB yte = False
sel.Find.Correc tHangulEndings = False
sel.Find.MatchA llWordForms = False
sel.Find.MatchS oundsLike = False
sel.Find.MatchW ildcards = False
sel.Find.MatchF uzzy = False
sel.Find.Find.E xecute(Replace= constants.wdRep laceAll)
wordDoc.SaveAs( ...some word file name...)
Can't say that this works as I typed because I haven't try it myself
but should give you a good start.
Make sure you run the makepy.py program in the
\python23\lib\s ite-packages\win32c om\client directory and install the
"MS Word 11.0 Object Library (8.3)" (or something equivalent). On my
computers, this is not installed automatically and I have to remember
to do it myself or else things won't work.
Good Luck.