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

Little Guy the_little_guy at gmx.com
Sat Jul 9 16:46:42 CEST 2011


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

----- Original Message -----
From: python-win32-request at python.org
Sent: 07/08/11 08:34 PM
To: python-win32 at python.org
Subject: python-win32 Digest, Vol 100, Issue 9

 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. (Tim Roberts) 2. Accessing standard Mail-application (Steffen Fr?mer) 3. Re: Accessing standard Mail-application (Tim Roberts) 4. Re: Accessing standard Mail-application (Steffen Fr?mer) 5. Re: win32print.StartDocPrinter (Anthony Sterrett) ---------------------------------------------------------------------- Message: 1 Date: Fri, 8 Jul 2011 10:49:32 -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: <4E17432C.705 at probo.com> Content-Type: text/plain; charset="UTF-8" Little Guy wrote: > > I'm trying to create a Python script using win32com that creates a > Word 2003 document. This will become part of a little bigger script > for work. After the document opens up, it is split into two columns, > then text is pasted in, taking up both columns. After this is done, > I'd like to move the insertion point to the end of that page. > ... > I have some of the code down, but need the part that moves the > insertion point to the end and inserts a new page as well as the > function to print the file. > > Basically, this is what I have, most of which I gathered onlin: You have the basic idea. You just need to plow through the online samples. > I've tried > using VBA Macro Recorder to produce similar code in VBA but I get > stuck when trying to port the code from VBA to Python. Your macro does nothing other than set up the columns. It doesn't do the text manipulation. > I've tried browsing Microsoft's COM Automation pages, but it feels > like I'm looking > for a needle in a hay stack, as the saying goes. I suppose I could > code this > functionality into a VBScript file and then call it from Python, but > I'd, much, rather > code everything in Python. If you are going to be doing a lot of this, then unfortunately you really need to become an expert in looking for needles in haystacks. The process of coming up with Python code This, I think, does what you were trying to do: import win32com.client as win32 word = win32.gencache.EnsureDispatch('Word.Application') word.Visible = True doc = word.Documents.Add() doc.PageSetup.TextColumns.SetCount (2) # Paste a bunch of text. rng = doc.Range(0,0) rng.Text = "Lots and lots of words. " * 200 # Collapse the range so we point at the end. rng.Collapse( win32.constants.wdCollapseEnd) # Insert a hard page break. rng.InsertBreak( win32.constants.wdPageBreak ) # Insert more words. rng.Text = "More words. " * 30 -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. ------------------------------ Message: 2 Date: Fri, 08 Jul 2011 21:04:45 +0200 From: Steffen Fr?mer <steffen at froemer.net> To: python-win32 at python.org Subject: [python-win32] Accessing standard Mail-application Message-ID: <4E1754CD.2020502 at froemer.net> Content-Type: text/plain; charset="iso-8859-1"; Format="flowed" Hi, 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. Actually i do following: app = "Outlook" mailObj = win32com.client.gencache.EnsureDispatch("%s.Application" % app) mail = mailObj.CreateItem(win32com.client.constants.olMailItem) mail.Recipients.Add("mail (at) domain.de") mail.Subject = "Subject" mail.Body = "Body Msg" mail.Attachments.Add('c:/temp/file.txt') But there are Systems, which don't use MS Outlook. Is there a way to access the standard mail application. Regards, Steffen -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-win32/attachments/20110708/cb36f4f7/attachment-0001.html> ------------------------------ Message: 3 Date: Fri, 8 Jul 2011 13:16:31 -0700 From: Tim Roberts <timr at probo.com> To: "python-win32 at python.org" <python-win32 at python.org> Subject: Re: [python-win32] Accessing standard Mail-application Message-ID: <4E17659F.50901 at probo.com> Content-Type: text/plain; charset="ISO-8859-1" 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? > But there are Systems, which don't use MS Outlook. > Is there a way to access the standard mail application. There is no "standard mail application". Lots of Windows systems (and most servers) don't run a mail application at all. You can try using MAPI; most of the popular mail apps support that The COM dispatch is "Mapi.Session". There are even some Python samples on using MAPI. However, to be completely general, you need to use smtplib to send to an external mail server. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. ------------------------------ Message: 4 Date: Fri, 08 Jul 2011 23:23:12 +0200 From: Steffen Fr?mer <steffen.froemer at gns-systems.de> To: python-win32 at python.org Subject: Re: [python-win32] Accessing standard Mail-application Message-ID: <4E177540.4020708 at gns-systems.de> Content-Type: text/plain; charset="iso-8859-1"; Format="flowed" 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? I found this on web: import urllib, webbrowser, win32api def mailto_url(to=None,subject=None,body=None,cc=None, att=None): """ encodes the content as a mailto link as described on http://www.faqs.org/rfcs/rfc2368.html """ url = "mailto: " + urllib.quote(to.strip(),"@,") sep = "?" if cc: url+= sep + "cc=" + urllib.quote(cc,"@,") sep = "&" if subject: url+= sep + "subject=" + urllib.quote(subject,"") sep = "&" if body: # Also note that line breaks in the body of a message MUST be # encoded with "%0D%0A". (RFC 2368) body="\r\n".join(body.splitlines()) url+= sep + "body=" + urllib.quote(body,"") sep = "&" return url txtTo = "mail (at) domain.de" txtSubject = "Test Subject" body = "Test body" txtCC = "cc_test (at) com.net" att = r'C:/Temp/test.txt' url = mailto_url(txtTo,txtSubject,body,txtCC) webbrowser.open(url,new=1) > >> But there are Systems, which don't use MS Outlook. >> Is there a way to access the standard mail application. > There is no "standard mail application". Lots of Windows systems (and > most servers) don't run a mail application at all. You can try using > MAPI; most of the popular mail apps support that The COM dispatch is > "Mapi.Session". There are even some Python samples on using MAPI. Thanks for this hint. I will try this. > > 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 -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-win32/attachments/20110708/e938ba4d/attachment-0001.html> ------------------------------ Message: 5 Date: Fri, 8 Jul 2011 20:34:49 -0700 From: Anthony Sterrett <vl.arandur at gmail.com> To: Tim Roberts <timr at probo.com> Cc: Python-Win32 List <python-win32 at python.org> Subject: Re: [python-win32] win32print.StartDocPrinter Message-ID: <CAN-=XHNuG9NB0yzNnoj1esoE5qkZCL2BtQqu03TuNAbproqwng at mail.gmail.com> Content-Type: text/plain; charset="iso-8859-1" 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. 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... On 6 July 2011 12:54, Tim Roberts <timr at probo.com> wrote: > Anthony Sterrett wrote: > > What are the available data types accepted by /tuple/ in > > win32print.StartDocPrinter(/hprinter, level, tuple/)? Or, if this is > > determined by my printer driver, how can I find this information? > > RAW and EMFSPOOL are predefined. The printer driver might define other > types, but few do so. > > > I am trying to hack together a program that will print a html file > > I've generated onto a 3x5 index card... code below: > > ... > > So what I'm really asking, if anyone can answer, is this: How do I > > turn my HTML file into something I can print? > > You have to render the HTML, just like a browser would. That, of > course, is not a trivial task, especially if you have tables and > stylesheets. You could use Internet Explorer to do this, or embed one > of the other browsers. > > Perhaps you should look at the wx.html.HtmlEasyPrinting module in > wxPython. It doesn't take arbitrary HTML, but it works for generating > reports and things. > > -- > Tim Roberts, timr at probo.com > Providenza & Boekelheide, Inc. > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-win32/attachments/20110708/57dfe39a/attachment.html> ------------------------------ _______________________________________________ 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 9 ******************************************** 



Regards, 
 Little Guy
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-win32/attachments/20110709/180e0381/attachment.html>


More information about the python-win32 mailing list