COM and MS Word

CTony anthony.evershed at npl.co.uk
Mon Apr 7 05:15:31 EDT 2003


It appears that some data files I need are in WordPerfect (.dat)
format, and I need to get them into Python for processing and later
entry into a database. I haven't been able to find a way of
interfacing to WordPerfect directly, but MS Word 2000 can read these
files...

Here's the snag, though. All the examples of Python/COM/Word usage
I've seen have involved pushing data into Word, rather than extracting
data *from* it. I know that the data field I need is x lines below a
known heading, so getting to the field is no problem:

finder = wd.Selection.Find
finder.Text = 'foo'
finder.Execute()
for n in range(x):
    wd.Selection.MoveDown
wd.Selection.HomeKey

get you to the beginning of the field, no problems. How, however, can
I select (block mark) and extract that line of text?

If it helps, I'm using Python 2.2, with win32all build 148, on Windows
NT 4 (though the resulting program will be used on Windows 2000 as
well)...

Many thanks,

Tony Evershed




More information about the Python-list mailing list