怎么用delphi找查word文档中的指定字符串,找到后将字符串改变颜色
时间:2011-12-18
来源:互联网
下面是一段查找替换程序,但就是不知道怎么替换同时改变颜色?
var vWordApp,Tbl:Variant;
i:integer;
FindText, MatchCase, MatchWholeWord, MatchWildcards, MatchSoundsLike,
MatchAllWordForms, Forward, Wrap, Format, ReplaceWith, Replace,matchkashida,matchdiacritics,matchAleFhamza,matchcontrol: OleVariant;
ItemIndex,FileName,Emp ,fmt :OleVariant ;
visible,Template,NewTemplate,DocuType: OleVariant;
Begin
// NewTemplate:=false;
// DocuType:=wdNewBlankDocument;
// Visible:=true;
// Template:='f:\lx\lx.dot';
//然后使用
// wordapplication1.documents.add(Template,NewTemplate,DocuType,Visible);
Emp:=EmptyParam;
fmt:=0;
FileName:='D:\doc1.doc';
wordapplication1.documents.Open(FileName,Emp,Emp,Emp,Emp,Emp,Emp,Emp,Emp,Emp,Emp,Emp,Emp,Emp,fmt);
wordapplication1.Visible:=true;
ItemIndex := 1;
WordDocument1.ConnectTo(WordApplication1.Documents.Item(ItemIndex));
//worddocument1.Range.Font.Color;
findtext:= '<#Name>';
MatchCase := False;
MatchWholeWord := True;
MatchWildcards := False;
MatchSoundsLike := False;
MatchAllWordForms := false;
Forward := true;
Wrap := wdFindContinue;
Format := False;
matchcontrol:=false;
ReplaceWith:= 'delphi';
//replacewith
Replace := wdReplaceAll;
matchkashida:=true;
matchdiacritics:=true;
matchAleFhamza:=true;
worddocument1.range.Find.Text:=findtext;
worddocument1.Range.Find.Font.Color:=200;
//worddocument1.Range.Font.Color:=200;
//wordapplication1.Selection.Font.Color:=200;
// WordDocument1.ActiveWindow.ActivePane.View.SeekView:=wdSeekCurrentPageHeader;
// WordDocument1.Range.Find.ClearFormatting;
// WordDocument1.Range.Find.Replacement.ClearFormatting;
worddocument1.range.find.execute( findtext, matchcase, matchwholeword,
matchwildcards, matchsoundslike, matchallwordforms, forward,
wrap, format, replacewith, replace,matchkashida,matchdiacritics,
matchAleFhamza,matchcontrol ) ;
end;
var vWordApp,Tbl:Variant;
i:integer;
FindText, MatchCase, MatchWholeWord, MatchWildcards, MatchSoundsLike,
MatchAllWordForms, Forward, Wrap, Format, ReplaceWith, Replace,matchkashida,matchdiacritics,matchAleFhamza,matchcontrol: OleVariant;
ItemIndex,FileName,Emp ,fmt :OleVariant ;
visible,Template,NewTemplate,DocuType: OleVariant;
Begin
// NewTemplate:=false;
// DocuType:=wdNewBlankDocument;
// Visible:=true;
// Template:='f:\lx\lx.dot';
//然后使用
// wordapplication1.documents.add(Template,NewTemplate,DocuType,Visible);
Emp:=EmptyParam;
fmt:=0;
FileName:='D:\doc1.doc';
wordapplication1.documents.Open(FileName,Emp,Emp,Emp,Emp,Emp,Emp,Emp,Emp,Emp,Emp,Emp,Emp,Emp,fmt);
wordapplication1.Visible:=true;
ItemIndex := 1;
WordDocument1.ConnectTo(WordApplication1.Documents.Item(ItemIndex));
//worddocument1.Range.Font.Color;
findtext:= '<#Name>';
MatchCase := False;
MatchWholeWord := True;
MatchWildcards := False;
MatchSoundsLike := False;
MatchAllWordForms := false;
Forward := true;
Wrap := wdFindContinue;
Format := False;
matchcontrol:=false;
ReplaceWith:= 'delphi';
//replacewith
Replace := wdReplaceAll;
matchkashida:=true;
matchdiacritics:=true;
matchAleFhamza:=true;
worddocument1.range.Find.Text:=findtext;
worddocument1.Range.Find.Font.Color:=200;
//worddocument1.Range.Font.Color:=200;
//wordapplication1.Selection.Font.Color:=200;
// WordDocument1.ActiveWindow.ActivePane.View.SeekView:=wdSeekCurrentPageHeader;
// WordDocument1.Range.Find.ClearFormatting;
// WordDocument1.Range.Find.Replacement.ClearFormatting;
worddocument1.range.find.execute( findtext, matchcase, matchwholeword,
matchwildcards, matchsoundslike, matchallwordforms, forward,
wrap, format, replacewith, replace,matchkashida,matchdiacritics,
matchAleFhamza,matchcontrol ) ;
end;
作者: totoking 发布时间: 2011-12-18
http://topic.csdn.net/t/20061126/11/5185772.html
看看这个吧, 我想一般回答没他的精辟了。
看看这个吧, 我想一般回答没他的精辟了。
作者: zhangqiwen 发布时间: 2011-12-18
我想让delphi在word中查找某个字符串,如查找到就将找到的字符串改变颜色,比如:红色
作者: totoking 发布时间: 2011-12-18
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28