Fazer uma PerguntaFazer uma Pergunta
 

RespondidoSpell Checker using word.

  • terça-feira, 19 de setembro de 2006 21:14FrankGroves Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     

    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);

    }

Respostas

  • quarta-feira, 20 de setembro de 2006 17:10Archimagus Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     Respondido

    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;
    }

Todas as Respostas

  • quarta-feira, 20 de setembro de 2006 0:13ahmedilyasMVP, ModeradorMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     

    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?

  • quarta-feira, 20 de setembro de 2006 16:55FrankGroves Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     

    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,

     

  • quarta-feira, 20 de setembro de 2006 17:10Archimagus Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     Respondido

    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;
    }

  • quarta-feira, 20 de setembro de 2006 17:12ahmedilyasMVP, ModeradorMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     

    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?

  • quarta-feira, 20 de setembro de 2006 18:42FrankGroves Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     

    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,

     

  • quarta-feira, 20 de setembro de 2006 18:58ahmedilyasMVP, ModeradorMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     
    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
  • quinta-feira, 21 de setembro de 2006 13:14FrankGroves Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     
    Would this work for a web form as well?
  • segunda-feira, 16 de outubro de 2006 13:56FrankGroves Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     
    If this isn't the right forum to post this addon question then please let me know where to post it.  Thanks!
  • segunda-feira, 16 de outubro de 2006 13:58ahmedilyasMVP, ModeradorMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     

    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