关于C#替换Word文本框中的内容(不使用Bookmark)疑问
来源:互联网 发布:java培训班北京 编辑:程序博客网 时间:2024/06/04 18:27
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/// <summary>
/// 查找并替换文本
/// </summary>
/// <param name="wordApp"></param>
/// <param name="oldStr"></param>
/// <param name="newStr"></param>
public
void
SearchReplace(
string
oldStr,
string
newStr)
{
#region 文字区域
object
replaceAll = WdReplace.wdReplaceAll;
wordApp.Selection.Find.ClearFormatting();
wordApp.Selection.Find.Text = oldStr;
wordApp.Selection.Find.Replacement.ClearFormatting();
wordApp.Selection.Find.Replacement.Text = newStr;
wordApp.Selection.Find.Execute(
ref
missing,
ref
missing,
ref
missing,
ref
missing,
ref
missing,
ref
missing,
ref
missing,
ref
missing,
ref
missing,
ref
missing,
ref
replaceAll,
ref
missing,
ref
missing,
ref
missing,
ref
missing);
#endregion
#region 文本框
StoryRanges sr = wordDoc.StoryRanges;
foreach
(Range r
in
sr)
{
Range r1 = r;
if
(WdStoryType.wdTextFrameStory == r.StoryType) //这句话用来判断什么的?
{
do
{
r1.Find.ClearFormatting();
r1.Find.Text = oldStr;
r1.Find.Replacement.ClearFormatting();
r1.Find.Replacement.Text = newStr;
if (r1.Find.Execute(
ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing, ref missing,
ref replaceAll, ref missing, ref missing, ref missing, ref missing))
{
break;//找到并替换后跳出循环,省点时间
}
else
{
r1 = r1.NextStoryRange;
}
//加上这个if语句可以提高一点效率,但还是比较慢
}
while
(r1 !=
null
);
}
}
#endregion
}
有哪位高手能解释下这段代码,我目前只会用,不理解,谢谢
<script type="text/javascript"><!--google_ad_client = "ca-pub-1944176156128447";/* cnblogs 首页横幅 */google_ad_slot = "5419468456";google_ad_width = 728;google_ad_height = 90;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
- 关于C#替换Word文本框中的内容(不使用Bookmark)疑问
- C#替换Word中的文本内容
- 踏踏实实学编程 基于C#操作Word文档中的Bookmark
- 利用Excel查找替换Word文本框里的内容
- Word 键入内容 不替换 选定内容 (不覆盖、不复写) 解决
- C#窗体打开word-替换标签内容
- 使用python把pdf转换为word然后替换word中的文字内容
- c#快速清除所有文本框中的内容
- C# 利用WORD模板和标签(bookmark) 批量生成WORD
- C#中操作Word(5)—— 利用BookMark对象写Word文档
- C#生成word查找替换中的问题
- C# 替换Word文档中的图片
- C# 替换Word文字【包含页眉、页脚、文本框、普通文字的替换】
- 使用POI替换word中的特定字符/文字)【改进】
- C#实现WORD文档的内容复制和替换
- c#对Aspose.Word替换书签内容的简单封装
- 关于ANT使用中的一点点疑问?
- 使用poi动态替换word指定文本内容
- C#用DataTable实现Group by数据统计
- 使用Kinect,Azure,Windows Phone和Windows8的家庭安全系统(翻译)
- 多重背包
- 我的Java开发学习之旅------>Java多线程下载文件 实例
- Ajax自定义无刷新控件实现
- 关于C#替换Word文本框中的内容(不使用Bookmark)疑问
- Android Binder 基础
- VMware Workstation 9.0.1 Bulid 894247安装、注册指南
- ASP.NET 4.0 Webform传统开发模式下如何压缩css, js
- Csharp:The .dat File using BinaryReader and BinaryWriter Convert to DataTable
- ASP.Net 实现伪静态方法及意义
- 进程间通信小结
- XAML中Button重绘为圆形
- Android dialog自定义样式