MSDN > フォーラム ホーム > Visual C# General > Spell Checker using word.
質問する質問する
 

回答済みSpell Checker using word.

  • 2006年9月19日 21: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日 17: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日 0: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日 16: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日 17: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日 17: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日 18: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日 18: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日 13:14FrankGroves ユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダル
     
    Would this work for a web form as well?
  • 2006年10月16日 13: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日 13: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