4
我在VB.net桌面應用程序中通過Interop使用Word 2007拼寫檢查器。使用默認語言(英文)時,它可以正常工作。如果我通過LanguageId將語言設置爲法語,它也可以。但如果我將它設置爲法語(加拿大)(Word.WdLanguageID.wdFrenchCanadian),則不起作用。沒有錯誤消息,它只是運行並且說文檔不包含錯誤。從Interop使用Word 2007拼寫檢查時某些語言不起作用
我知道如果我將完全相同的文本粘貼到Word本身並使用法語(加拿大)字典運行它,它會發現錯誤。爲什麼字典不起作用對我來說是一個謎。
全部下面的代碼:
Public Shared Function SpellCheck(ByVal text As String, ByVal checkGrammar As Boolean) As String
' If there is no data to spell check, then exit sub here.
If text.Length = 0 Then
Return text
End If
Dim objWord As Word.Application
Dim objTempDoc As Word.Document
' Declare an IDataObject to hold the data returned from the
' clipboard.
Dim iData As IDataObject
objWord = New Word.Application()
objTempDoc = objWord.Documents.Add
objWord.Visible = False
' Position Word off the screen...this keeps Word invisible
' throughout.
objWord.WindowState = 0
objWord.Top = -3000
' Copy the contents of the textbox to the clipboard
Clipboard.SetDataObject(text)
' With the temporary document, perform either a spell check or a
' complete
' grammar check, based on user selection.
With objTempDoc
.Content.Paste()
.Activate()
.Content.LanguageID = Word.WdLanguageID.wdFrenchCanadian
If checkGrammar Then
.CheckGrammar()
Else
.CheckSpelling()
End If
' After user has made changes, use the clipboard to
' transfer the contents back to the text box
.Content.Copy()
iData = Clipboard.GetDataObject
If iData.GetDataPresent(DataFormats.Text) Then
text = CType(iData.GetData(DataFormats.Text), _
String)
End If
.Saved = True
.Close()
End With
objWord.Quit()
Return text
End Function
法語(加拿大)已安裝,它被選爲我在Word中啓用的語言之一,並且它是通常用於Word本身的字典。 挑選一些我沒有的東西(如瑞典語)給出了與法語(加拿大)相同的行爲。就好像自動化不能看到字典,即使它在那裏。 – Tridus 2010-03-25 19:48:07