Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
I'm trying to use the spellCheck feature provided by word to correct a string that is not in English, the problem is that when i use the spellCheck function i get the Spelling and Grammar dialog which requires user input and i don't want that to happen.
This is my code
using System.Collections.Generic;
using Microsoft.Office.Interop.Word;
using Word = Microsoft.Office.Interop.Word;
using TobyCL.ro.toby.StringOperations;
namespace namespace.ro.toby
{
    class WordProofing:IProof
    {
        private readonly Word.Application _wordApp;
        private readonly Word.Document _wordDoc;
        private static object _oEndOfDoc = "\\endofdoc";
        public WordProofing()
        {
 
            _wordApp = new Word.Application {Visible = false};
            _wordDoc = _wordApp.Documents.Add();
        }
        public void Close()
        {
            object obj = Word.WdSaveOptions.wdDoNotSaveChanges;
            _wordDoc.Close(ref obj);
            _wordApp.Quit(ref obj);
        }
        #region Implementation of IProof
 
        public string Proof(string proofText)
        {
            Range wRng = _wordDoc.Bookmarks.get_Item(ref _oEndOfDoc).Range;
            wRng.Text = proofText;
            _wordDoc.CheckSpelling(IgnoreUppercase: true,AlwaysSuggest:false);
            string str = wRng.Text;
            wRng.Text = "";
            return str;
        }
        #endregion
    }
}
 
It worked last week when i wrote it, but in the meantime i uninstalled Office proofing tools, and reinstalled it. So i'm thinking that maybe the a setting i have to set or maybe i accidentally change something in my code (but i doubt the last one).
 
Thanks in adavance
Posted 16-Feb-12 1:26am
toby311.3K

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

I've solved it but it's really really slow, so any new ideas are welcomed.
using Microsoft.Office.Interop.Word;
    class WordProofing
    {
        private Application _wordApp;
        private readonly Document _wordDoc;
        private static object _oEndOfDoc = "\\endofdoc";
        public WordProofing()
        {
 
            _wordApp = new Application { Visible = false };
            _wordDoc = _wordApp.Documents.Add();
        }
        public void Close()
        {
            _wordDoc.Close(WdSaveOptions.wdDoNotSaveChanges);
            _wordApp.Quit();
        }
 
        public string Proof(string proofText)
        {
            Range wRng = _wordDoc.Bookmarks.get_Item(ref _oEndOfDoc).Range;
            wRng.Text = proofText;
            ProofreadingErrors spellingErros = wRng.SpellingErrors;
            foreach (Range spellingError in spellingErros)
            {
                SpellingSuggestions spellingSuggestions =
                                                            _wordApp.GetSpellingSuggestions(spellingError.Text,IgnoreUppercase:true);
 
                foreach (SpellingSuggestion spellingSuggestion in spellingSuggestions)
                {
                    spellingError.Text = spellingSuggestion.Name;
                    break;
                }
            }
 
            string str = wRng.Text;
            wRng.Text = "";
            return str;
        }
    }
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 295
1 DamithSL 265
2 CPallini 235
3 Maciej Los 190
4 George Jonsson 170
0 OriginalGriff 5,415
1 DamithSL 4,422
2 Maciej Los 3,820
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,911


Advertise | Privacy | Mobile
Web02 | 2.8.141216.1 | Last Updated 16 Feb 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100