the-generalist.com

  • Increase font size
  • Default font size
  • Decrease font size
joomla templates, wordpress themes, drupal, datalife engine, graphics, seo,
Home

Using Python with Microsoft Word (Simple Example)

E-mail Print PDF

I was kind of surprised the today when I had a localization request dealing with Microsoft Word documents. Not because of the request, but because after all these years writing scripts to help with localization tasks, I had never written one for Word. It turns out using Python with Word is as simple as using it with other MS Office Apps. You'll need to setup pywin32. Here's a simple example that opens the currently active Word document and iterates through the paragraphs printing them out.

import win32com.client
 
#Launch or Connect to Microsoft Word.
#I set Visible = True so you don't have to
#go into the task manager to close it if something
#goes wrong
MSWord = win32com.client.Dispatch("Word.Application")
MSWord.Visible = True
 
#Get the Active Document (Last one you had selected)
Document = MSWord.ActiveDocument
 
#Iterate through the paragraphs printing them.
for paragraph in Document.Paragraphs:
    Text = paragraph.Range.Text
    print Text

 

This may error on the print statement if it hits Unicode characters that your console doesn't support.

Last Updated on Thursday, 30 June 2011 01:16  

Comments  

 
0 #76 TahliaSmall 2017-11-22 05:39
I have checked your website and i have found some duplicate content, that's why you
don't rank high in google, but there is a tool that can help you to create 100% unique content, search for: Boorfe's tips unlimited content
Quote
 
 
0 #75 Car ecu repair tool 2017-11-22 02:00
Theae are genuinely enormous iceas in concerning blogging.
You have touched some fastidious points here. Any way keep up wrinting.
Quote
 
 
0 #74 Hermalindo 2017-11-15 18:17
?
¡De verdad! Dedícate a otra cosa. Esto ni por lo menos se vincula con buen fin.
Quote
 
 
0 #73 Iphone 7 kiliflari 2017-11-13 03:53
Greetings! Very helpful advice in this particular article!

It's the little changes that produce the most important changes.
Thanks a lot for sharing!

My web-site Iphone 7 kiliflari: http://www.baktit.info/applenin-son-modeli-iphone-7-ve-iphone-7-plus-kirmizi/
Quote
 
 
0 #72 Accelerator Problems 2017-11-07 19:33
Great blog! Is your theme custom made or did you download it from somewhere?
A design like yours with a few simple adjustements would really make my blog jump out.
Please let me know where you got your design. Thank you
Quote
 
 
0 #71 Swen 2017-10-31 02:41
Howdy! I could have sworn I've been to this website before but after looking at many of the posts I realized it's new to me.
Nonetheless, I'm certainly pleased I stumbled upon it and I'll
be book-marking it and checking back frequently!

Feel free to surf to my web-site - Swen: http://topcams.Ukmilfcams.com/index.php?a=stats&u=kurthoutman
Quote
 
 
0 #70 backlinks 2017-10-30 10:42
But after utilizing the?r service ? h?d my website on the f?rst pag? of G??gle a couple weeks
after placing my ?rder. The thing h?re to keep in m?nd i?
that it wou?d please take ? wide range of at work
so that you can monitor individual keywords manually,
h?nce the more wo?k that you could simplify, the better.
?ignificanc? of Website Back-links and SEOY?u might be
wondering how effective websites or website
pages will be witho?t back-links and SEO.

Have a look at my page - backlinks: https://www.fiverr.com/cldisplay_seo/build-100-manual-backlinks-for-your-ebay-shopify-etsy-store
Quote
 
 
0 #69 Jeannie 2017-10-14 19:41
No matter if some one searches for his viktal thing, thus he/she needs to
bbe available that in detail, so that thing is maintained over here.
Quote
 
 
0 #68 broderie 2017-09-26 04:11
Great beat ! I would like to apprentice while you
amend your site, how could i subscribe for a blog web site?

The account helped me a acceptable deal. I have been tiny bit familiar of
this your broadcast provided vivid clear concept
Quote
 
 
0 #67 jewelry 2017-09-25 16:55
Be it ?our mother, wife, sister or dau?hter, women are special and so when the gift presented to them ?e.
You can complete a se?ection from the large choice available because it one particular
while using fam?us ?ccessories which sea?ch g?o? with whatever you have on.
If you spend any attention t? fashion jewelry trends you know brown diamonds have realized their way into t?e hearts of numerous
from fashion je?elry: http://stores.ebay.com/DIAMOND-SCENE ??signers,
to celebrities towards the average consumer.
Quote
 

Add comment


Security code
Refresh

Main Menu