Microsoft Developer Network > 포럼 홈 > Visual C# General > Spell Checker using word.
질문하기질문하기
 

답변됨Spell Checker using word.

  • 2006년 9월 19일 화요일 오후 9:14FrankGroves 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     

    I came across this code on the net and was wondering if anyone could help me tweak this to search more than just one textbox.

    Thanks


    protected void Button1_Click(object sender, EventArgs e)

    {

    Word.Application app = new Word.Application();

    app.Visible = false;

    object template = Missing.Value;

    object newTemplate = Missing.Value;

    object documentType = Missing.Value;

    object visible = true;

    object optional = Missing.Value;

    object saveChanges = false;

    object originalFormat = Missing.Value;

    object routeDocument = Missing.Value;

    Word._Document doc1 = app.Documents.Add(ref template, ref newTemplate, ref documentType, ref visible);

    doc1.Words.First.InsertBefore(TextBox1.Text);

    doc1.CheckSpelling(

    ref optional, ref optional, ref optional, ref optional, ref optional, ref optional,

    ref optional, ref optional, ref optional, ref optional, ref optional, ref optional);

    object first = 0;

    object last = doc1.Characters.Count - 1;

    TextBox1.Text = doc1.Range(ref first, ref last).Text;

    app.Quit(ref saveChanges, ref originalFormat, ref routeDocument);

    }

답변

  • 2006년 9월 20일 수요일 오후 5:10Archimagus 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     답변됨

    I would suspect something like this would work for you. assuming this function is part of the form that contains the text boxes you want to check.

    foreach (Object o in Controls)
    {
       if (!(o is TextBox))
          continue;
       TextBox tb = (o as TextBox);
       doc1.Words.First.InsertBefore(tb.Text);
       doc1.CheckSpelling( ref optional, ref optional, ref optional, ref optional, ref optional, ref optional, ref optional, ref optional, ref optional, ref optional, ref optional, ref optional);
       object first = 0;
       object last = doc1.Characters.Count - 1;
       tb.Text = doc1.Range(ref first, ref last).Text;
    }

모든 응답

  • 2006년 9월 20일 수요일 오전 12:13ahmedilyasMVP, 중재자사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     

    do you mean from this line?

    doc1.Words.First.InsertBefore(TextBox1.Text);

     

    are you able to explain a tad more in what you like to achieve so we can better assist you?

  • 2006년 9월 20일 수요일 오후 4:55FrankGroves 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     

    I've got a form that I'd like to use MS Word's spell check capability to check the entire form not just one textbox, like the example does.  I was wondering how to go about adding more textboxes to this code for it to check instead of just checking textbox1.

    Thanks,

     

  • 2006년 9월 20일 수요일 오후 5:10Archimagus 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     답변됨

    I would suspect something like this would work for you. assuming this function is part of the form that contains the text boxes you want to check.

    foreach (Object o in Controls)
    {
       if (!(o is TextBox))
          continue;
       TextBox tb = (o as TextBox);
       doc1.Words.First.InsertBefore(tb.Text);
       doc1.CheckSpelling( ref optional, ref optional, ref optional, ref optional, ref optional, ref optional, ref optional, ref optional, ref optional, ref optional, ref optional, ref optional);
       object first = 0;
       object last = doc1.Characters.Count - 1;
       tb.Text = doc1.Range(ref first, ref last).Text;
    }

  • 2006년 9월 20일 수요일 오후 5:12ahmedilyasMVP, 중재자사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     

    if I understand correctly, you wish to have say, several textboxes on your form, and you wish to do some word searching in MS Word, using the values from these several textboxes on your application form correct? please do correct me if I am wrong.

    If this is the case, you can go through each textbox on the form, and then use your code to get the value of the textbox, in the for each loop, and then do the search based on that. Example (I'm unsure if it should be from this line but hopefully itll give you an insight):

     

    foreach(Control currentControl in this.Controls)

    {

       if (currentControl.GetType() == typeof(TextBox))

       {

          TextBox theTextBox = (TextBox)currentControl;  

          //rest of code here...

          doc1.Words.First.InsertBefore(theTextBox.Text);

          //and other code here

       }

    }

     

    Does this help/make sense?

  • 2006년 9월 20일 수요일 오후 6:42FrankGroves 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     

    I've got a form that I'd like to use MS Word's spell check capability to check the entire form not just one textbox, like the example does.  I was wondering how to go about adding more textboxes to this code for it to check instead of just checking textbox1.

    Thanks,

     

  • 2006년 9월 20일 수요일 오후 6:58ahmedilyasMVP, 중재자사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
    the code I supplied does just that, of course you would need to add the textboxes to the form, then code then goes through each textbox on the form and does the search I believe
  • 2006년 9월 21일 목요일 오후 1:14FrankGroves 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
    Would this work for a web form as well?
  • 2006년 10월 16일 월요일 오후 1:56FrankGroves 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
    If this isn't the right forum to post this addon question then please let me know where to post it.  Thanks!
  • 2006년 10월 16일 월요일 오후 1:58ahmedilyasMVP, 중재자사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     

    ASP.NET questions should be posted:

    http://forums.asp.net for a better answer and since the site is dedicated for ASP.NET, you'll be sure to get a good answer since thats where the ASP.NET experts hang out