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; }
|
|---|
| 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 | |
by Anonymous Monk on Feb 22, 2010 at 04:25 UTC | |
by ikegami (Patriarch) on Feb 22, 2010 at 05:33 UTC | |
by Anonymous Monk on Feb 22, 2010 at 10:36 UTC | |
by cdarke (Prior) on Feb 22, 2010 at 13:57 UTC | |
by Anonymous Monk on Feb 22, 2010 at 05:22 UTC |