locked
Spell Check using OpenOffice RRS feed

  • Question

  • I am using a piece of code for spell checking I found here several years ago (below).
    Ms Word is used for the spell checking.
    I would like to use for instance OpenOffice (or other free tool) for the same purpose.

    Anyone can tell how to?

    Code:

               Dim oWord As Object = Nothing
                Dim oDoc As Object = Nothing
                Dim oData As IDataObject = Nothing
                Dim OrigTop As Long = 0
                Try
                    oWord = System.Activator.CreateInstance(Type.GetTypeFromProgID("Word.Application"))
                    Dim oDocuments As Object = oWord.[GetType]().InvokeMember("Documents", BindingFlags.[Default] Or BindingFlags.GetProperty, Nothing, oWord, Nothing)
                    oDoc = oDocuments.[GetType]().InvokeMember("Add", BindingFlags.[Default] Or BindingFlags.InvokeMethod, Nothing, oDocuments, Nothing)
                    oWord.Visible = False
                    OrigTop = oWord.Top
                    oWord.WindowState = 0
                    oWord.Top = -3000
                    Clipboard.SetDataObject(TextField)
                    oWord.Visible = True

                     For Each p As Process In Process.GetProcessesByName("winword")
                        'It's hard to decide if the current ms word document is not open by user/
                        Dim v = SetParent(p.Handle, Handle)
                    Next

                    With oDoc
                        .Content.Paste()
                        .Activate()
                        .CheckGrammar()
                        .Content.Copy()
                        oData = Clipboard.GetDataObject
                        If oData.GetDataPresent(DataFormats.Text) Then
                            ReturnText = CType(oData.GetData(DataFormats.Text), String)
                        End If
                        .Saved = True
                        .Close()
                    End With

                    oWord.Visible = False
                    oWord.Top = OrigTop
                    oWord.Quit()
                    'MessageBox.Show("Spelling check complete!")


    Appleforce

    • Moved by Stanly Fan Tuesday, January 22, 2019 7:43 AM
    Tuesday, January 8, 2019 1:46 PM

All replies

  • Hi,

    >> I would like to use for instance OpenOffice (or other free tool) for the same purpose.

    First of all, could you tell me where do you want to implement spell checking? In a textbox?

    If so, usually, we can achieve it via using the wpf control "TextBox" in winform. Here is the steps you can refer to.

    First, drag an "ElementHost" into the form.

    Then, modify the code in "Form1.vb" like this:

        Public Class Form1
            Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
                ' Declare a wpf control "TextBox"
                Dim txt As Windows.Controls.TextBox = New Windows.Controls.TextBox()
                ' Turn on spell checking
                txt.SpellCheck.IsEnabled = True
                ' Set the "TextBox" as ElementHost's "Child" Property 
                ElementHost1.Child = txt
            End Sub
        End Class

    After completing the above operation, the text you enter in the TextBox will be checked whether spelling is right, and you can modify the wrong spelling by right-click.

    Result:

    Besides, If you want to use "OpenOffice"(via using "NHunspell"), to achieve this requirement, you can also refer to this link:

    Spell Check, Hyphenation, and Thesaurus for .NET with C# and VB Samples - Part 1: Single Threading

    Regards,

    Kyle


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, January 9, 2019 8:23 AM
  • Thanks for replying.

    I am trying your Elementhost tip, but I acn't make it working.

    What could I be missing? Do I need some connection to what?

    Appleforce

    Saturday, January 12, 2019 6:11 AM
  • Hi,

    Here is a demo you can refer to. You can download it from this link.

    Regards,

    Kyle


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, January 14, 2019 1:30 AM
  • Sorry to say, I cannot make i work.

    Apparently you are using a more recent vversion of VB.Net then the one I am using, VB.Net 10

    Appleforce

    Monday, January 14, 2019 8:50 AM
  • Hi,

    According to your description, your issue is more related to VB10. It will be more appropriate to ask your question at VBForums.

    Thank you for your understanding.

    Regards,

    Kyle


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, January 14, 2019 9:09 AM