MSWord and Python

Jeff Shannon jeff at ccvcorp.com
Tue Feb 26 15:10:56 EST 2002


Thomas Guettler wrote:

> Ricky wrote:
>
> > The client side document is include in Python online documents.
>
> Sorry I didn't understand you. Is there are library for creating word
> documts without COM? This would be nice since I could create the
> documents on unix, too. What's its's name?

No, what he meant was that the pythoncom documentation includes some
examples of automating Word/Excel.  They're COM examples, though, and
will only work on Windows, just as Word and Excel will only work on
Windows.  (Oh, wait, there's Mac versions too -- do those have any
COM-like functionality?  I don't know...)  Anyhow, you will need to use
Windows/COM to do what you want.

If this is anything more than a simple one-off throwaway script, do
yourself a favor and buy "Python Programming on Win32", by Mark Hammond
and Andy Robinson.  It goes into a lot of detail on using COM from
Python, including extended examples of using Excel, and to a lesser
extent Word.  If you're going to be doing this often, or are doing a
non-trivial-sized project, it will be well worth the investment.

For details of Word's API/object model, you'll need to either see the
included help files, or MSDN.  This will be aimed at VisualBasic users,
but it's mostly pretty easy to translate.  There's also a COM browser
built in to PythonWin, which can give you some help, but it's a little
sparse (it just lists objects, methods, and parameters, you have to
figure out when/how to use them yourself, but it's good for
double-checking that method that you almost remember...)

Jeff Shannon
Technician/Programmer
Credit International





More information about the Python-list mailing list