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实用实例浅析
责任编辑:仲衡 来源: ieee.org.cn
相关推荐

2009-08-19 13:49:14

C#操作注册表

2009-08-18 17:34:25

C#操作符重载应用

2009-08-18 17:20:17

C#操作符重载

2009-08-27 17:50:09

interface接口

2009-08-18 13:06:17

C#枚举类型

2009-08-13 17:52:13

C#构造函数

2009-08-17 18:15:23

C# 枚举使用

2009-09-09 10:53:25

C# MessageB

2009-08-14 11:29:28

C#创建Windows

2009-08-28 16:30:24

C#线程

2009-08-19 10:42:08

C#操作Word表格

2009-09-03 14:28:23

C#日期格式化

2009-08-03 09:17:30

ASP.NET Ses

2009-08-19 10:16:15

C#操作Word

2009-08-19 10:25:14

C#操作Word

2009-08-19 10:46:48

C#操作Word表格

2009-06-16 13:30:32

REST无状态

2009-08-19 11:13:49

C#操作Word

2009-08-19 11:34:06

C#操作Word

2009-08-19 09:42:52

C#操作Word书签
点赞
收藏

51CTO技术栈公众号