C#操作Word的一点认识

C#操作Word的一点认识主要向你介绍了C#操作Word的内涵,以及C#操作Word的具体的方法的应
首页 新闻资讯 行业资讯 C#操作Word的一点认识

C#操作Word的内涵:C#操作Office套件的时候都需要用到COM组件,需要在项目里添加相应的COM组件。用C#在Word里查找指定关键字的方法有两种:Selection对象和Range对象。

C#操作Word之Selection对象的用法:

复制

// C#   internal void SelectionFind()  {    string strFind = "find me";    Word.Find fnd = ThisApplication.Selection.Find;     fnd.ClearFormatting();     fnd.Text = strFind;    object missingValue = Type.Missing;     if (fnd.Execute(ref missingValue, ref missingValue,      ref missingValue, ref missingValue, ref missingValue,      ref missingValue, ref missingValue, ref missingValue,      ref missingValue, ref missingValue, ref missingValue,      ref missingValue, ref missingValue, ref missingValue,      ref missingValue))   {   MessageBox.Show("Text found.");    }    else   {   MessageBox.Show("The text could not be located.");     }  }
  • 1.

  • 2.

  • 3.

  • 4.

  • 5.

  • 6.

  • 7.

  • 8.

  • 9.

  • 10.

  • 11.

  • 12.

  • 13.

  • 14.

  • 15.

  • 16.

  • 17.

  • 18.

  • 19.

  • 20.

  • 21.

  • 22.

  • 23.

C#操作Word之Range对象的用法:

复制

// C#      internal void RangeFind()     {  Word.Range rng = ThisDocument.Paragraphs[2].Range;  Word.Find fnd = rng.Find;  fnd.ClearFormatting();  object missingValue = Type.Missing;  object findStr = "find me";  if (fnd.Execute(ref findStr,   ref missingValue, ref missingValue,      ref missingValue, ref missingValue, ref missingValue,      ref missingValue, ref missingValue, ref missingValue,      ref missingValue, ref missingValue, ref missingValue,      ref missingValue, ref missingValue, ref missingValue))  {    MessageBox.Show("Text found.");  }  else {    MessageBox.Show("Text not found.");   }    rng.Select();   }
  • 1.

  • 2.

  • 3.

  • 4.

  • 5.

  • 6.

  • 7.

  • 8.

  • 9.

  • 10.

  • 11.

  • 12.

  • 13.

  • 14.

  • 15.

  • 16.

  • 17.

  • 18.

  • 19.

  • 20.

  • 21.

  • 22.

  • 23.

C#操作Word的一点体会就向你介绍到这里,希望对你了解和学习C#操作Word有所帮助。

【编辑推荐】

  1. C#操作Word书签实例浅析

  2. C#操作Word表的实例浅析

  3. C#操作Word表格的常见操作

  4. C#操作Word表格的彪悍实例

  5. C#操作Word实用实例浅析

6    2009-08-19 11:23:12    C#操作Word