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 #65 started making money 2017-08-20 03:11
I the efforts you have put in this, thanks for all the great content.
Quote
 
 
0 #64 Deidre 2017-08-20 02:01
Plenty of water, hot broth makes you also feel full.
Quote
 
 
0 #63 mens leather Shirts 2017-07-25 10:14
Very descriptive post, I enjoyed that a lot. Will there be a
part 2?

my website mens leather Shirts: http://www.startblogg.se/index.php?a=stats&u=jaimiepuig7875
Quote
 
 
0 #62 http://tinyurl.com 2017-07-18 09:17
Você enganou descaradamente. Diz art. Muito bem-agradecido.
Quote
 
 
0 #61 leather purses 2017-07-11 11:16
I am truly glad to read this website posts which consists of tons of helpful data,
thanks for providing these kinds of data.

My webpage; leather purses: http://www.tjhjlymc.com/comment/html/index.php?page=1&id=8237
Quote
 
 
0 #60 Twyla 2017-07-07 04:00
I like the valuable information you provide in your articles.
I'll bookmark your weblo and check again here
regularly.I'm quite sure I will learn plenty of new stuff right here!
Best of luck for the next!

Feel free to visit my web site :: Twyla: http://mundo.adjaranet.com/user/PMTJulie203/
Quote
 
 
0 #59 Zachariasz Wszolek 2017-07-06 22:34
It is appropriate time to make a few plans for the long run and it's time to be
happy. I've read this publish and if I may I wish to recommend you some attention-grabbing things or
suggestions. Maybe you can write subsequent articles relating to this article.

I want to learn more things about it!
Quote
 
 
0 #58 Anemonalove 2017-07-06 19:46
Hi guys! Who wants to meet me? I'm live at HotBabesCams.com, we
can chat, you can watch me live for free, my nickname is Anemonalove , here is my
photo:

https://3.bp.blogspot.com/-u5pGYuGNsSo/WVixiO8RBUI/AAAAAAAAAFA/JWa2LHHFI2AkHParQa3fwwHhVijolmq8QCLcBGAs/s1600/hottest%2Bwebcam%2Bgirl%2B-%2BAnemonalove.jpg
Quote
 
 
0 #57 Napoleon Szukalski 2017-07-02 02:08
What's up, of course this paragraph is genuinely
good and I have learned lot of things from it about blogging.
thanks.
Quote
 
 
0 #56 Olen 2017-07-01 10:44
It's amazing too visit this site and rwading the views of alll
mates on the topic of this post, while I am also keen oof
getting experience.

My web-site ... Olen: http://www.printerservice.com.br/userinfo.php?uid=133412
Quote
 

Add comment


Security code
Refresh

Main Menu