How can I do French and English Spell Checking using MS Word from Python

Tim Golden tim.golden at viacom-outdoor.co.uk
Wed Oct 20 04:19:18 EDT 2004


[Pater Maximus]
| I have been knocking my brains out on this one. I just got it 
| to work while
| putting together a reply to you. That just goes to prove the
| Shakespeare/typing monkeys paradigm works in Python too:)
| 
| I figured it out by using the "dot completion" in Delphi to 
| discover that
| .Selection.LanguageID was acceptable.

[... snip sample code ...]

I'm afraid I can't say whether dot-completion is available in
Python IDEs since I don't use any, but I *can* help you with the
language constant.

A bit of background. (Skip this if you already understand early-
and late-binding of COM objects in pywin32.) When you use 
win32com.client.Dispatch, there are two options: rely on a generated
module which acts as a proxy for the COM object in question; or
build the classes etc. as you go along only when you need them.
(This last is called dynamic dispatch). If you're using the proxy 
module, then constants (such as wdFrench) are available as 
win32com.client.constants.wdFrench. If you're using dynamic dispatch
the constants are not available and you have to hardwire them as
you have done.

To generate the proxy module, you have two approaches: either use
the makepy.py module from the win32com package (on my system it's
in c:\python23\lib\site-packages\win32com\client\makepy.py); or
force the generation when you instantiate the object in your code,
using the gencache.EnsureDispatch method. Eg,

<code>
import win32com.client

word = win32com.client.gencache.EnsureDispatch ("Word.Application")
word.Selection.LanguageId = win32com.client.constants.wdFrench

#
# Do your spell-checking here
#

</code>

Hope this helps you a bit more.

TJG

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________



More information about the Python-list mailing list