我正在使用 VB.net 桌面应用程序中的 Interop 使用 Word 2007 拼写检查器。当使用默认语言(英语)时,它可以正常工作。如果我通过 LanguageId 将语言设置为法语,它也可以正常工作。但是,如果我将其设置为法语(加拿大)(Word.WdLanguageID.wdFrenchCanadian),它就无法工作。没有错误消息,它只是运行并说文档不包含错误。
我知道它是有错误的,如果我将完全相同的文本粘贴到 Word 中并使用法语(加拿大)字典运行它,它会发现错误。为什么这个字典不起作用,对我来说有点神秘。
以下是完整代码:
我知道它是有错误的,如果我将完全相同的文本粘贴到 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