COM file references

Matt m.wetherill at salfordNOSPAM.acNOSPAM.uk
Wed Feb 20 04:29:27 EST 2002


Hi group,
I'd just like to introduce myself - I'm just learning python and really like
the language, but I'm very much a newbie (to both python and programming),
so apologies if my queries seem astonishingly stupid!

Anyway to my problem (or the python related one anyway :-):

I have a requirement to convert ms word docs to raw text in order to allow
further processing of the text file.  I figured the best way to do this was
to use python to access word via COM and do a 'save-as'.  The following code
works fine from the interactive prompt (python 2.2, Office 2k)

import win32com.client
w=win32com.client.Dispatch("Word.Application")
w.Visible=1
w.Documents.Open("c:\\test.doc")
#save file as text file - number '5' is position of word to text converter
in the word 'file type' dialogue
w.ActiveDocument.SaveAs ("c:\\test.txt", 5)
w.ActiveDocument.Close(SaveChanges=0)

However, I really need to turn this into a function to which I can pass an
input file name and path, and an output file name and path.

This is troubling me - however I try, I can't work out how to pass the path
and file to the 'Documents.Open' expression (or vice-versa)

If anyone could offer any guidance I would really appreciate it. - Apologies
for the astonishingly simple nature of the query!

cheers

Matt





More information about the Python-list mailing list