开发者

Some languages don't work when using Word 2007 Spellcheck from Interop

I'm using the Word 2007 spellchecker via Interop in a VB.net desktop app. When using the default language (English), it works fine. If I set the language to French via LanguageId, it also works. But if I set it to French (Canadian) (Word.WdLanguageID.wdFrenchCanadian), it doesn't work. There's no error message, it simply runs and says the document contains no errors.

I know it does, if I paste the exact same text into Word itself and run it with the French (Canadian) dictionary, it finds errors. Just why that dictionary doesn't work is kind of a mystery to me.

Full code below:

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


Are the languages which don't work actually installed for the spellchecker?

And if you try to change the language to for example German? (or Italian but not Italian (Switzerland))

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜