【问题标题】:Some languages don't work when using Word 2007 Spellcheck from Interop从 Interop 使用 Word 2007 拼写检查时,某些语言不起作用
【发布时间】:2011-01-31 10:08:03
【问题描述】:

我在 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

【问题讨论】:

    标签: .net vb.net interop office-2007 spell-checking


    【解决方案1】:

    是否为拼写检查器实际安装了不起作用的语言?

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

    【讨论】:

    • 法语(加拿大)已安装,它被选为我在 Word 中启用的语言之一,它是 Word 本身通常使用的字典。选择我没有的东西(比如瑞典语)会产生与法语(加拿大)相同的行为。就好像自动化无法看到字典,即使它在那里。
    猜你喜欢
    • 1970-01-01
    • 2010-10-29
    • 1970-01-01
    • 1970-01-01
    • 2014-05-28
    • 1970-01-01
    • 1970-01-01
    • 2022-01-02
    • 1970-01-01
    相关资源
    最近更新 更多