我在VB.net桌面应用程序中通过Interop使用Word 2007拼写检查程序。使用默认语言(英语)时,它可以正常工作。如果我通过LanguageId将语言设置为法语,它也可以。但是,如果我将它设置为法语(加拿大)(Word.WdLanguageID.wdFrenchCanadian),它就不起作用。没有错误消息,它只是运行并说文档没有错误。
我知道它确实如此,如果我将完全相同的文本粘贴到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
答案 0 :(得分:0)
拼写检查器实际上是否安装了不起作用的语言?
如果您尝试将语言更改为德语? (或意大利语,但不是意大利语(瑞士))