[python-win32] Word document with columns and page break. (Little Guy)

Zev Spitz shivisi at nana10.co.il
Mon Jul 11 08:52:01 CEST 2011


This isn't really something you should be searching for in PythonWin. 
Rather, this is part of the Word object model, which PythonWin lets you use.

For more information about the Word object model:
1) Open Word
2) Open the VBA editor (Alt+F11)
3) from the menus: Help -> Microsoft Visual Basic Help
4) Search for Word object model
That will give you a visual overview of the object model.

Also, pressing F2 brings up the Object Browser, which lets you see 
methods/properties of a particular object.
You can also search for objects/methods/properties by name, using the 
second dropdown.

Re: Selection vs. Range
Just about anything you can do with the Selection object, you can do 
with the Range object. The difference is that the Selection object is a 
property of the Application, or the Window - it refers to the currently 
selected text in the window. The Range object is some part of the 
document, unrelated to whether it has been selected in the Window. If, 
for example, you Collapse the Selection to the end of the Selection, 
that will be reflected in the window of the application. Collapsing the 
Range will have no visible effect.

Re: Columns
I would suggest that you have to think about the steps you would use to 
do this manually.
In order to have different numbers of columns in different parts of a 
document, you need to insert a section break, and apply the columns to a 
given section.
So, in code:

#Insert a new section + page break
doc.Range.InsertBreak(win32.constants.wdSectionBreakNextPage)
#Apply two columns to the first section
doc.Sections(1).PageSetup.TextColumns.SetCount(2)


Hope this helps,
Zev Spitz


On 7/10/2011 1:00 PM, python-win32-request at python.org wrote:
> Send python-win32 mailing list submissions to
> 	python-win32 at python.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
> 	http://mail.python.org/mailman/listinfo/python-win32
> or, via email, send a message with subject or body 'help' to
> 	python-win32-request at python.org
>
> You can reach the person managing the list at
> 	python-win32-owner at python.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of python-win32 digest..."
>
>
> Today's Topics:
>
>     1. Re: Word document with columns and page break. (Little Guy)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Sat, 09 Jul 2011 14:46:42 +0000
> From: "Little Guy"<the_little_guy at gmx.com>
> To: python-win32 at python.org
> Subject: Re: [python-win32] Word document with columns and page break.
> Message-ID:<20110709144643.26730 at gmx.com>
> Content-Type: text/plain; charset="utf-8"
>
> Mr. Roberts,
>
>   Thanks for the assist. As I am not an expert at this, yet, it's a bit difficult
>   knowing where to start looking for the information.
>
>   Actually, I have most of the text processing portion of the code down, and
>   omitted it from my, earlier, post so as to not overwelm the message.
>
>   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 tried using python-win32's help system's, search feature and search for insert
>   but did not see any suggestions could up.
>
>   Anyways, I appretiate the suggestions.
>
>   Regards,
>   Little Guy


More information about the python-win32 mailing list