如何用delphi找查word文档中的指定字符串,找到后将字符串改变颜色
怎么用delphi找查word文档中的指定字符串,找到后将字符串改变颜色
下面是一段查找替换程序,但就是不知道怎么替换同时改变颜色?
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;
------解决方案--------------------
http://topic.****.net/t/20061126/11/5185772.html
看看这个吧, 我想一般回答没他的精辟了。
------解决方案--------------------
这个就是调用WORD函数的问题。
下面是一段查找替换程序,但就是不知道怎么替换同时改变颜色?
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;
------解决方案--------------------
http://topic.****.net/t/20061126/11/5185772.html
看看这个吧, 我想一般回答没他的精辟了。
------解决方案--------------------
这个就是调用WORD函数的问题。