简体   繁体   中英

How to change MS Word spelling check language through Ole in Delphi?

I utilize Microsoft Office 2007 Standard Edition in Delphi 2009 through Ole automation to check spelling. Checking works for my system language (Russian). However, I can't find a way to change it to English.

That's how I create my spell checking object.

constructor CWordSpellChecker.Create;
begin
     try
          MsWordApp := CreateOleObject('Word.Application'); //MsWordApp is OleVariant
          MsWordApp.Options.IgnoreMixedDigits := False;
          MsWordApp.Visible := False;
          FActive := true;
          MsWordApp.Documents.Add;
     except
          on E: Exception do begin
               MessageDlg('Cannot Connect to MS Word', mtError, [mbOk], 0);
               FActive := false;
          end;
     end;
end;

This is the method that actually checks.

function CWordSpellChecker.IsCorrect(_Text: String): Boolean;
begin
     result := False;

     if FActive then
          if MsWordApp.CheckSpelling(_Text) then
               result := True;
end;

Could you please tell me what I need to add to my code to change the language to English?

The following code seems to work for me, using D7 and Word 2007 (I don't have a later Delphi version on this machine). My default Word language is English UK .

  MSWord.Selection.TypeText('The colour is blue');  //  "colour" is the correct spelling in UK English, but not
                                                    //  US English

  MSWord.ActiveDocument.AttachedTemplate.LanguageID := wdEnglishUS;
  MSWord.ActiveDocument.AttachedTemplate.NoProofing := False;
  MSWord.Selection.LanguageID := wdEnglishUS;
  MSWord.ActiveDocument.CheckSpelling;

. This code pops up the spelling correction dialog on colour and offers to "correct" it to the US spelling color .

Various flavours of English are listed in the Word import unit Word2000.Pas, namely

  wdEnglishAUS = $00000C09;
  wdEnglishBelize = $00002809;
  wdEnglishCanadian = $00001009;
  wdEnglishCaribbean = $00002409;
  wdEnglishIreland = $00001809;
  wdEnglishJamaica = $00002009;
  wdEnglishNewZealand = $00001409;
  wdEnglishPhilippines = $00003409;
  wdEnglishSouthAfrica = $00001C09;
  wdEnglishTrinidad = $00002C09;
  wdEnglishUK = $00000809;
  wdEnglishUS = $00000409;
  wdEnglishZimbabwe = $00003009;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM