小弟我利用网上大大们的代码(实现对word的控制)在编译时报错,没有事先定义reword,程序中用到reword.line.add reword.line.count等变量或参数,请问在delphi中要use哪个*.dcu
函数代码如下:
{功能:使用newText替换docText内容bSimpleReplace:true时仅做简单的替换,false时对新文本进行换行处理}function PrnWordReplace(docText,newText:String;bSimpleReplace:boolean=false):boolean;var i:Integer;begin if bSimpleReplace then begin //简单处理,直接执行替换操作 try wApp.Selection.Find.ClearFormatting; wApp.Selection.Find.Replacement.ClearFormatting; wApp.Selection.Find.Text := docText; wApp.Selection.Find.Replacement.Text :=newText; wApp.Selection.Find.Forward := True; wApp.Selection.Find.Wrap := wdFindContinue; wApp.Selection.Find.Format := False; wApp.Selection.Find.MatchCase := False; wApp.Selection.Find.MatchWholeWord := true; wApp.Selection.Find.MatchByte := True; wApp.Selection.Find.MatchWildcards := False; wApp.Selection.Find.MatchSoundsLike := False; wApp.Selection.Find.MatchAllWordForms := False; wApp.Selection.Find.Execute(Replace:=wdReplaceAll); result:=true; except result:=false; end; exit; end; //自动分行 reWord.Lines.Clear; reWord.Lines.Add(newText); try //定位到要替换的位置的后面 wApp.Selection.Find.ClearFormatting; wApp.Selection.Find.Text := docText; wApp.Selection.Find.Replacement.Text := ''; wApp.Selection.Find.Forward := True; wApp.Selection.Find.Wrap := wdFindContinue; wApp.Selection.Find.Format := False; wApp.Selection.Find.MatchCase := False; wApp.Selection.Find.MatchWholeWord := False; wApp.Selection.Find.MatchByte := True; wApp.Selection.Find.MatchWildcards := False; wApp.Selection.Find.MatchSoundsLike := False; wApp.Selection.Find.MatchAllWordForms := False; wApp.Selection.Find.Execute; wApp.Selection.MoveRight(wdCharacter,1); //开始逐行插入 for i:=0 to reWord.Lines.Count-1 Do begin //插入当前行 wApp.Selection.InsertAfter(reWord.Lines[i]); //除最后一行外,自动加入新行 if i<reWord.Lines.Count-1 then wApp.Selection.InsertAfter(#13); end; //删除替换位标 wApp.Selection.Find.ClearFormatting; wApp.Selection.Find.Replacement.ClearFormatting; wApp.Selection.Find.Text := docText; wApp.Selection.Find.Replacement.Text := ''; wApp.Selection.Find.Forward := True; wApp.Selection.Find.Wrap := wdFindContinue; wApp.Selection.Find.Format := False; wApp.Selection.Find.MatchCase := False; wApp.Selection.Find.MatchWholeWord := true; wApp.Selection.Find.MatchByte := True; wApp.Selection.Find.MatchWildcards := False; wApp.Selection.Find.MatchSoundsLike := False; wApp.Selection.Find.MatchAllWordForms := False; wApp.Selection.Find.Execute(Replace:=wdReplaceAll); result:=true; except result:=false; end;end;
函数代码如下:
{功能:使用newText替换docText内容bSimpleReplace:true时仅做简单的替换,false时对新文本进行换行处理}function PrnWordReplace(docText,newText:String;bSimpleReplace:boolean=false):boolean;var i:Integer;begin if bSimpleReplace then begin //简单处理,直接执行替换操作 try wApp.Selection.Find.ClearFormatting; wApp.Selection.Find.Replacement.ClearFormatting; wApp.Selection.Find.Text := docText; wApp.Selection.Find.Replacement.Text :=newText; wApp.Selection.Find.Forward := True; wApp.Selection.Find.Wrap := wdFindContinue; wApp.Selection.Find.Format := False; wApp.Selection.Find.MatchCase := False; wApp.Selection.Find.MatchWholeWord := true; wApp.Selection.Find.MatchByte := True; wApp.Selection.Find.MatchWildcards := False; wApp.Selection.Find.MatchSoundsLike := False; wApp.Selection.Find.MatchAllWordForms := False; wApp.Selection.Find.Execute(Replace:=wdReplaceAll); result:=true; except result:=false; end; exit; end; //自动分行 reWord.Lines.Clear; reWord.Lines.Add(newText); try //定位到要替换的位置的后面 wApp.Selection.Find.ClearFormatting; wApp.Selection.Find.Text := docText; wApp.Selection.Find.Replacement.Text := ''; wApp.Selection.Find.Forward := True; wApp.Selection.Find.Wrap := wdFindContinue; wApp.Selection.Find.Format := False; wApp.Selection.Find.MatchCase := False; wApp.Selection.Find.MatchWholeWord := False; wApp.Selection.Find.MatchByte := True; wApp.Selection.Find.MatchWildcards := False; wApp.Selection.Find.MatchSoundsLike := False; wApp.Selection.Find.MatchAllWordForms := False; wApp.Selection.Find.Execute; wApp.Selection.MoveRight(wdCharacter,1); //开始逐行插入 for i:=0 to reWord.Lines.Count-1 Do begin //插入当前行 wApp.Selection.InsertAfter(reWord.Lines[i]); //除最后一行外,自动加入新行 if i<reWord.Lines.Count-1 then wApp.Selection.InsertAfter(#13); end; //删除替换位标 wApp.Selection.Find.ClearFormatting; wApp.Selection.Find.Replacement.ClearFormatting; wApp.Selection.Find.Text := docText; wApp.Selection.Find.Replacement.Text := ''; wApp.Selection.Find.Forward := True; wApp.Selection.Find.Wrap := wdFindContinue; wApp.Selection.Find.Format := False; wApp.Selection.Find.MatchCase := False; wApp.Selection.Find.MatchWholeWord := true; wApp.Selection.Find.MatchByte := True; wApp.Selection.Find.MatchWildcards := False; wApp.Selection.Find.MatchSoundsLike := False; wApp.Selection.Find.MatchAllWordForms := False; wApp.Selection.Find.Execute(Replace:=wdReplaceAll); result:=true; except result:=false; end;end;
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货