[python-win32] Word document with columns and page break.
The Little Guy
the_little_guy at gmx.com
Tue Jul 12 05:31:50 CEST 2011
Mr. Roberts,
Tim Roberts Wrote:
> 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.
I'm beginning to relize the fact that I have to figure out the translation
as documentation is, as has been explained, comes only from the Microsoft
side.
> 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.
Yes, and unfortunately, I'm not an artist :) I tried looking around for
some sort of VBA to python converter and came up with the following:
http://vb2py.sourceforge.net/ Unfortunately, it does not appear to be
VBA compatible, at this time.
Thanks for your help,
Little Guy
-----Original Message-----
From: python-win32-bounces+the_little_guy=gmx.com at python.org
[mailto:python-win32-bounces+the_little_guy=gmx.com at python.org] On Behalf Of
python-win32-request at python.org
Sent: Monday, July 11, 2011 8:11 PM
To: python-win32 at python.org
Subject: python-win32 Digest, Vol 100, Issue 12
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: Accessing standard Mail-application (Vernon Cole)
2. Re: Word document with columns and page break. (Tim Roberts)
3. Re: win32print.StartDocPrinter (Tim Roberts)
4. Re: win32print.StartDocPrinter (python at bdurham.com)
5. Re: Word document with columns and page break. (Little Guy)
(The Little Guy)
----------------------------------------------------------------------
Message: 1
Date: Mon, 11 Jul 2011 09:58:55 -0600
From: Vernon Cole <vernondcole at gmail.com>
To: Steffen Fr?mer <steffen.froemer at gns-systems.de>
Cc: python-win32 at python.org
Subject: Re: [python-win32] Accessing standard Mail-application
Message-ID:
<CAH-ZgAdD7pnoF7ZxUmRpQEKqXhpJ8M+Ed-jjWEeNVJ4Gv-zSCg at mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
On Fri, Jul 8, 2011 at 3:23 PM, Steffen Fr?mer <
steffen.froemer at gns-systems.de> wrote:
> On 07/08/2011 10:16 PM, Tim Roberts wrote:
>
> Steffen Fr?mer wrote:
>
> i tried to access standard mail application to write a mail.
> I know the machanism with urllib, but there is no regular way to add
> attachments.
>
> How would you do that with urllib?
>
>
> However, to be completely general, you need to use smtplib to send to an
> external mail server.
>
> This is no option, because there is noch smtp-server withouf
> authentication and we need to send mails from different users.
>
> Regards,
> Steffen
>
> Steffen:
You (who ever you mean when you say "we") should probably set up a
dedicated smtp-server for your group. If many of your users have OUTLOOK,
then you may have an exchange server which could be used for that purpose.
In my own case, it was fairly easy to get that administrator to turn on smtp
support on the company's exchange server. I wrote a little private
in-company-email module which was pre-programmed with the name of the
exchange server and with our company's authentication. The smtplib calls
were embedded within it.
To add an attachment, you need MIME -- which was invented for that exact
purpose. There is a whole library of python standard modules for doing
that. See http://docs.python.org/library/email.html and an example in
http://code.activestate.com/recipes/52243-sending-multipart-mime-email-<http
://code.activestate.com/recipes/52243-sending-multipart-mime-email-with-smtp
lib-and-mime/>
with-smtplib-and-mime/<http://code.activestate.com/recipes/52243-sending-mul
tipart-mime-email-with-smtplib-and-mime/>
That ought to be much easier than hacking OUTLOOK -- especially if you
must support version updates, etc.
--
Vernon
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.python.org/pipermail/python-win32/attachments/20110711/5a309d63
/attachment-0001.html>
------------------------------
Message: 2
Date: Mon, 11 Jul 2011 13:59:49 -0700
From: Tim Roberts <timr at probo.com>
To: Python-Win32 List <python-win32 at python.org>
Subject: Re: [python-win32] Word document with columns and page break.
Message-ID: <4E1B6445.2030507 at probo.com>
Content-Type: text/plain; charset="UTF-8"
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.
------------------------------
Message: 3
Date: Mon, 11 Jul 2011 14:04:59 -0700
From: Tim Roberts <timr at probo.com>
To: Python-Win32 List <python-win32 at python.org>
Subject: Re: [python-win32] win32print.StartDocPrinter
Message-ID: <4E1B657B.4090006 at probo.com>
Content-Type: text/plain; charset="ISO-8859-1"
Anthony Sterrett wrote:
> I'm not sure how to use the wx.html.HtmlEasyPrinting module, I'm sorry
> to say. The documentation is less than helpful, although that may well
> be attributed to my newbishness over their lack of documentation.
Have you downloaded wxPython? Did you install the wxPython demo? There
is an example of virtually every wxPython type in that demo, including
HtmlEasyPrinting. For more detailed help, you should probably go to the
wxPython mailing list.
> So suppose I decided to embed, say, Google Chrome into my program, to
> utilize its printing capabilities. How would I go about doing that? :3
> I've never had to embed a browser in my code before...
You'd have to go searching. The major browsers have interfaces that let
an application get access to the same object model that Javascript code
sees, which would allow you to trigger a "print". I'm not really
convinced that's the best way. The browsers tend to be very, very large.
How complicated is the thing you are printing? If you're just printing
text in a 3x5 card format, it's probably just as easy to do it with
Windows GDI calls. You could even create a PDF. That's what I tend to
do, because PDFs are so universal. When I create PDF, it looks the same
everywhere. There are several good PDF libraries for Python.
--
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.
------------------------------
Message: 4
Date: Mon, 11 Jul 2011 17:24:19 -0400
From: python at bdurham.com
To: "Python-Win32 List" <python-win32 at python.org>
Subject: Re: [python-win32] win32print.StartDocPrinter
Message-ID: <1310419459.24818.2150638645 at webmail.messagingengine.com>
Content-Type: text/plain; charset="us-ascii"
Anthony,
Dabo (dabodev.com) is an open source GUI framework built on top of
wxPython.
Dabo has a very impressive report writer.
Malcolm
------------------------------
Message: 5
Date: Mon, 11 Jul 2011 20:10:24 -0700
From: "The 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.
(Little Guy)
Message-ID: <BAFFAB4B05384E58B93A80E5A0AC4CAE at BLASTER7>
Content-Type: text/plain; charset="us-ascii"
Mr. Spitz,
Thanks for the suggestions, I tried it and found the object model for word
and I've begun to explore, little by little. Visually, being able to look
at the objects, methods, properties, etc, is very helpful.
For some reason my initial reply to Mr. Roberts, did not properly get stored
and sorted in the email list hierarchy, and ended up at the top. Hopefully,
this reply will be properly sorted. If not, is there a good email client,
that will properly take into consideration <message-id email headers so that
my replies don't bounce all over the email list or is this something that
needs to be changed in the python-win32 mail list setup page?
As you can see, I'm preaty new at this :)
Thanks,
Little Guy
-----Original Message-----
From: python-win32-bounces+the_little_guy=gmx.com at python.org
[mailto:python-win32-bounces+the_little_guy=gmx.com at python.org] On Behalf Of
python-win32-request at python.org
Sent: Monday, July 11, 2011 3:00 AM
To: python-win32 at python.org
Subject: python-win32 Digest, Vol 100, Issue 11
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)
(Zev Spitz)
----------------------------------------------------------------------
Message: 1
Date: Mon, 11 Jul 2011 09:52:01 +0300
From: Zev Spitz <shivisi at nana10.co.il>
To: python-win32 at python.org
Subject: Re: [python-win32] Word document with columns and page break.
(Little Guy)
Message-ID: <BLU0-SMTP12901B590F573959A41DA3085450 at phx.gbl>
Content-Type: text/plain; charset="UTF-8"; format=flowed
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
------------------------------
_______________________________________________
python-win32 mailing list
python-win32 at python.org
http://mail.python.org/mailman/listinfo/python-win32
End of python-win32 Digest, Vol 100, Issue 11
*********************************************
------------------------------
_______________________________________________
python-win32 mailing list
python-win32 at python.org
http://mail.python.org/mailman/listinfo/python-win32
End of python-win32 Digest, Vol 100, Issue 12
*********************************************
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-win32/attachments/20110711/5b2203f8/attachment-0001.html>
More information about the python-win32
mailing list