johnpeterdinesh has asked for the wisdom of the Perl Monks concerning the following question:

i want check spelling of a word using Win32::OLE::Const 'Microsoft Word';

i'm getting spelling suggestion for wrongly spelled words in EnglishUS language as default.
 but i want to change the default language as EnglishUK.
 or i want to set the spell check language as EnglishUK.

But i want in EnglishUS.

Please Help..

Thanks in advance.



This is my script for check spell in English US


use strict; use Win32::OLE; use Win32::OLE::Const 'Microsoft Word'; # Win32::OLE->Option(Warn => 0); my $word = Win32::OLE->new('Word.Application', 'Quit') or die; # $word-> {DisplayAlerts} = 0; # $word-> {WindowState} = 0; $word-> {Visible} = 0; my $doc = $word->Documents->Add(); my $range = $doc->{Content}; $range->{Text} = 'Analyser'; $range->InsertParagraphAfter(); my $paras = $doc->Paragraphs; foreach my $para (in $paras) { print ">> " , $para->Range->{Text}; my $text=$para->Range->{Text}; $para->Range->{LanguageID}=2057; my @errors=&spellcheck($word,$text); my @guesses; if($#errors==0) { foreach my $word(@errors) { my $guesses = $word->{'guesses'}; @guesses = @$guesses; } print "[@guesses]\n"; } else { print "[@guesses]\n"; } } <>; $doc-> Saved(0); $doc-> Close(0); $word-> Quit(); sub spellcheck { my $self = shift; my $text = shift; my $msword = $self; my @errors; while ($text =~ m/(\S+)\b/g) { my $offset = pos($text) - length($1) + 1; my $term = { term => $1, offset => $offset }; # If is correctly spelled proceed to the next word next if $msword->CheckSpelling($term -> {term}); # Otherwise look for spelling suggestions my $suggestions = $msword->GetSpellingSuggestions($term -> {te +rm},LanguageID => 2057); # No suggestions: if (!$suggestions || !$suggestions -> {Count}) { $term -> {type} = 'none'; $term -> {guesses} = []; push @errors, $term; # Some suggestions: } else { my @suggest; foreach (in $suggestions) { push @suggest, $_->{Name}; } $term -> {type} = 'guess'; $term -> {guesses} = \@suggest; push @errors, $term; } } return @errors; }
  • Comment on How to get spelling suggestions in EnglishUK language as default in Win32::OLE
  • Download Code

Replies are listed 'Best First'.
Re: How to get spelling suggestions in EnglishUK language as default in Win32::OLE
by ikegami (Patriarch) on Feb 21, 2010 at 23:07 UTC

    When it comes to remote controlling Word, a useful tool is its macro recorder. Record the change you want to make, look at the macro, then Perlify it.

      Thanks for your quick reply. But i want as perl code.
        First you need to know what to do. That's what the macro recorder tells you. Then you can code it in Perl. If you have problems with that, come back with your new problem.
        The easy way: 1) get macro 2) translate to perl