[python-win32] Word document with columns and page break.

Tim Roberts timr at probo.com
Mon Jul 11 22:59:49 CEST 2011


Little Guy wrote:
>
> I wish there was some sort of pictorial object, property, hierarchy for
> python-win32 somewhere as it may be a great assist to newbies to visually
> see what objects and properties go where.  I think Java used to have
> something
> similar, at least I saw something like that in the late 90s.
>
> I never would have imagined, that inserting the break would be done
> from the
> /*rng*/ section, as demonstrated here: /*rng.InsertBreak(
> win32.constants.wdPageBreak )*/
>
> I was totally off thinking that it would be done from doc section as
> show here:
> /*doc.PageSetup.TextColumns.SetCount (2)*/

I'd like to amplify Zev's reply, which was right on.

What you're talking about there is not part of Python, or Python-Win32. 
There's nothing in Python called "InsertBreak"  Those commands, methods,
and properties are all part of Microsoft Word.  Microsoft has decided
what the methods are and how they are used.  What Python-Win32 lets you
do is treat the COM objects in Word as if they were real Python objects,
but you have to look to Word's help information to figure out how they work.

And as I said before, it is a bit of an art to translate the existing
Word sample code (which is all C++, or C#, or VB) into Python.

Even those constants (like win32.constants.wdPageBreak) are not
built-in.  When you use EnsureDispatch to create a COM object, the COM
stuff in Python-Win32 scans the library that contains the object to look
for all of the predefined constants.

> I tried using python-win32's help system's, search feature and search
> for insert
> but did not see any suggestions could up.

No, of course not.  If you Google for "Word object model", you'll get to
the top-level MSDN page about programming Word.  All of the Office
applications are complicated, but Microsoft has done a pretty good job
of providing a COM interface for every feature in the application.

-- 
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.



More information about the python-win32 mailing list