Open existing Word document, modify and save.

gsal salgerman at gmail.com
Tue Jan 15 19:01:02 CET 2008


New to Python and new to Win32. Help please.

O.k., so this might seem like one of those "can you do my homework"
kind of postings, except that is not homework, it is officework.

I have been reading the Core Python book and I am really excited about
starting my next project with Python, instead of tcl/tk/Fortran/C.
While I can see how to use it for scientific computing and have gone
with the NumPy and SciPy tutorials, I am having a hard time with
Win32.

Attempted to read some of the documentation for Win32 and while the
basic stuff talks about creating a document, I did not see how to open
an existing document and modify certain parts of it...and then it
seems that it got very complicated (for me) really quick.  Sure, it
seems powerful, but all I need is a small part of it, I think.

Here is the thing. Here at the office, we have computer programs to
generate spec data and the Applications people have MS-Word documents
in a very specific format where they would like to put such spec
data.

Initially, I was using merge fields and VB macros, until they stopped
working when newer (non-backwards-compatible) versions came along;
then, I switched to generating *.xml out of the original *.doc file,
breaking it appart, modifying it and gluing back together...this is
very laborious task and I have to go through the whole exercise,
should the application people modify the original *.doc

So, basically, I am looking for a way to work directly with the
original *.doc, assuming I know everything about it...which I do; in
fact, I have it and can also modify it, should I need to bookmark it
or otherwise modify as needed.

How to go about it?

What's the python code to open an existing document, modify it and
save it back?

how does the Word document needs to be bookmarked/formatted so that it
can be modified? For example, after the computer program has been run
and the new, say, "machine rating" calculated, I need to deposit such
value in a very specific spot in the Word document.

I presume somebody out there already does this and is willing to
provide some code?.

Thank you very much in advance.

gsal



More information about the Python-list mailing list