下面是调用word模版的程序,但是跟你要实现的可能有一定的差别,以下仅供参考:procedure TForm1.Button2Click(Sender: TObject);//按钮事件
var fn,i:OleVariant;
begin
with WordApplication1 do
begin
try
Connect();
fn:='d:\小蔡\wordprt\wordot\01.dot';//指定已建模板的路径。
i:=false;//当i为true或零并且已有指定模板,系统根据所建模板再重新建一个模板,
//若以前没有建模板则系统将会出现有关文档不存在或文档路径出错等信息
//若i为false或1并且已有指定模板,系统将会启动所指定模板。
Documents.Add(fn,i);
Replace('Edit1',Edit1.Text);//替换文本
Replace('Edit2',Edit2.Text);
Replace('Edit3',memo1.Text);
finally
Visible:=True;
Disconnect();
end;
end;
end;procedure TForm1.Replace(Source,Dest:string);//replace函数
var FindText,MatchCase,MatchWholeWord,MatchWildCards,MatchSoundsLike,
MatchAllWordForms,FForward,Wrap,Format,ReplaceWith,Replace,
MatchKaShida,MatchDiacritics,MatchAlefHamza,MatchControl:OleVariant;
What,Which,Count,CName:OleVariant;
begin
with WordApplication1 do
begin
FindText:=Source;
MatchCase:=True;
MatchWholeWord:=False;
MatchAllWordForms:=False;
MatchSoundsLike:=False;
FForward:=True;
Wrap:=False;
Format:=False;
//ReplaceWith:='';
replaceWith:=dest;
replace:=true;
//Replace:=False;
MatchKaShida:=False;
MatchDiacritics:=False;
MatchAlefHamza:=False;
MatchControl:=False;
Selection.Find.Execute(FindText,MatchCase,MatchWholeWord,
MatchWildCards,MatchSoundsLike,
MatchAllWordForms,FForward,wrap,Format,
ReplaceWith,Replace);
//Selection.TypeText(Dest);该语句和前面的两条语句结合后word中被替换的文字
是长文本,而如果用现有的语句,则word中被替换的文本最长为504个字节。
What:=wdGotoPage;
Which:=wdGotoNext;
Count:=1;
CName:='';
Selection.GoTo_(What,Which,Count,CName);
end;
end;
var fn,i:OleVariant;
begin
with WordApplication1 do
begin
try
Connect();
fn:='d:\小蔡\wordprt\wordot\01.dot';//指定已建模板的路径。
i:=false;//当i为true或零并且已有指定模板,系统根据所建模板再重新建一个模板,
//若以前没有建模板则系统将会出现有关文档不存在或文档路径出错等信息
//若i为false或1并且已有指定模板,系统将会启动所指定模板。
Documents.Add(fn,i);
Replace('Edit1',Edit1.Text);//替换文本
Replace('Edit2',Edit2.Text);
Replace('Edit3',memo1.Text);
finally
Visible:=True;
Disconnect();
end;
end;
end;procedure TForm1.Replace(Source,Dest:string);//replace函数
var FindText,MatchCase,MatchWholeWord,MatchWildCards,MatchSoundsLike,
MatchAllWordForms,FForward,Wrap,Format,ReplaceWith,Replace,
MatchKaShida,MatchDiacritics,MatchAlefHamza,MatchControl:OleVariant;
What,Which,Count,CName:OleVariant;
begin
with WordApplication1 do
begin
FindText:=Source;
MatchCase:=True;
MatchWholeWord:=False;
MatchAllWordForms:=False;
MatchSoundsLike:=False;
FForward:=True;
Wrap:=False;
Format:=False;
//ReplaceWith:='';
replaceWith:=dest;
replace:=true;
//Replace:=False;
MatchKaShida:=False;
MatchDiacritics:=False;
MatchAlefHamza:=False;
MatchControl:=False;
Selection.Find.Execute(FindText,MatchCase,MatchWholeWord,
MatchWildCards,MatchSoundsLike,
MatchAllWordForms,FForward,wrap,Format,
ReplaceWith,Replace);
//Selection.TypeText(Dest);该语句和前面的两条语句结合后word中被替换的文字
是长文本,而如果用现有的语句,则word中被替换的文本最长为504个字节。
What:=wdGotoPage;
Which:=wdGotoNext;
Count:=1;
CName:='';
Selection.GoTo_(What,Which,Count,CName);
end;
end;
你把它改改,加上个循环就搞定!!!!!!!
D:\Program Files\Borland\Delphi5\Demos\Activex\Oleauto\Word8 你看看这个例子,是否很需要??