有些语言在使用Interop的Word 2007拼写检查时无法正常工作。

4
我正在使用 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
1个回答

0

这些不起作用的语言实际上是否已经安装了拼写检查器?

如果您尝试将语言更改为例如德语(或意大利语但不是意大利语(瑞士)),会发生什么?


已安装了加拿大法语,它被选为我在Word中启用的语言之一,并且通常是Word本身使用的字典。选择我没有的语言(如瑞典语)会产生与加拿大法语相同的行为。好像自动化看不到字典,尽管它存在。 - Tridus

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接