Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Spell checker
Message
Information générale
Forum:
ASP.NET
Catégorie:
Formulaires
Titre:
Divers
Thread ID:
00968168
Message ID:
00968181
Vues:
10
Alexandre,

I just finished a spell-check module that I implemented for a client. I looked at some 3rd party tools, but wound up using Word Automation (we knew that all users would have Word on their machines).

I strongly recommend a separate module in VB.NET. VB.NET is generally better for OLE Automation than C#.
I have a function where I pass a string to be checked. The function returns an arraylist of words that are caught...
Public Function SpellCheck(ByVal cText As System.String)

      Dim WordApp As New Word.Application    ' object reference for MS Word
      Dim rngRange As Word.Range             ' need range object for spell checking 
      Dim aWordList As New ArrayList         ' array list of misspelled words

 
      WordApp.Documents.Add()                   ' add a document and insert the text to be spell-checked
      rngRange = WordApp.ActiveDocument.Range
      rngRange.InsertAfter(cText)
      Dim SpellCollection As Word.ProofreadingErrors   ' MS Word proofreading collection
      SpellCollection = rngRange.SpellingErrors
      If SpellCollection.Count > 0 Then
          Dim iword As Integer
          For iword = 1 To SpellCollection.Count               ' populate the arraylist with the words that MS word reported
              aWordList.Add(SpellCollection.Item(iword).Text)
          Next
      End If
      WordApp.Quit(False)                  ' close WORD 

      Return aWordList                   ' bring back the arraylist

 End Function
I also have a function that allows users to add words to their Word custom dictionary...
 Public Function AddWordToSpellCheck(ByVal cNewWord As System.String)

        ' when words are 'added' to the MS word dictionary, they actually go to the custom dictionary
        ' it's normally in the C:\Documents and Settings\Kevin\Application Data\Microsoft\Proof folder, as CUSTOM.DIC
        ' it's nothing more than a text file, so we just need to open and insert a line with the new word

        '  I thought there would be a separate function in Word Automation to add a word to a custom dictionary,
        ' but never found one.  Someone on another forum suggested that since the custom dictionary is just a text file,
        '  to just open it up and add the word
        '   The contents should probably be re-sorted after the insertion takes place....


  Dim WordApp As New Word.Application

   Dim oDictionary As Word.Dictionary
   Dim cstring As System.String

    For Each oDictionary In WordApp.CustomDictionaries          ' should only be just one
      cstring = oDictionary.Path + "\" + oDictionary.Name     ' get the location of the custom dictionary ,and the name of it
    Next

    Dim w As StreamWriter = File.AppendText(cstring)          ' open a streamwriter, add the word, then close the stream
    w.WriteLine(cNewWord)
    w.Flush()
    w.Close()
    WordApp.Quit(False)
    End Function
If you need anything else, try some searches on MSDN, as there are several examples of this up there. Hope this helps...
Kevin
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform