not quite random
nothing in particular

 


December 2002
Sun Mon Tue Wed Thu Fri Sat
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        
Nov   Jan










Subscribe to "not quite random" in Radio UserLand.

Click to see the XML version of this web page.

Click here to send an email to the editor of this weblog.

jenett.radio.randomizer - click to visit a random Radio weblog - for information, contact randomizer@coolstop.com

Blogchalk:
Portsmouth, NH, US




 

Monday, December 16, 2002

MS Word from Python

Note: this assumes you have python, win32all, and MS Word all installed properly.

Running Word from python is incredibly easy.

import win32com.client
# Start the application.
app = win32com.client.Dispatch('Word.Application')
# Open a document.
doc = app.Documents.Add('c:\path\to\document\test.doc')
# Or:
app.ChangeFileOpenDirectory('c:\path\to\document\')
doc = app.Documents.Add('test.doc')
# To save as HTML (filtered; i.e. without most of the MS cruft)
# Note: I don't know if the type-number is portable??
doc.SaveAs('test.html', 10) ## 10 == HTML-Filtered
doc.Close(0) ## 0 == don't save changes?
app.Quit()

This will all run "invisibly". If you want to display the app while doing all of this, set app.Visible = 1 somewhere near the top. If you simply want to fetch the text from the document, use doc.Content.Text. It will return a Unicode string and it's worth noting that those "smart quotes" have no representation in ASCII so you might have to be careful decoding it.

2:21:16 PM   #  


Click here to visit the Radio UserLand website. © Copyright 2003 Brian St. Pierre.
Last update: 1/3/2003; 8:34:39 AM.