用Server页的Word组控件
var
a,b:olevariant;
begin
a:=emptyparam;
b:=false;
wordapplication1.connect;
wordapplication1.visible:=true;
wordapplication1.documents.add(a,b);
worddocument1.connectto(wordapplication1.documents.item(1));
worddocument1.range.insertafter('你查询的内容'+#13+#10);
worddocument1.tables.add(wordapplication1.selection.range,2,2);
end;这是一个简单的例子,至于细节你可以自己去研究,相信不难
var
a,b:olevariant;
begin
a:=emptyparam;
b:=false;
wordapplication1.connect;
wordapplication1.visible:=true;
wordapplication1.documents.add(a,b);
worddocument1.connectto(wordapplication1.documents.item(1));
worddocument1.range.insertafter('你查询的内容'+#13+#10);
worddocument1.tables.add(wordapplication1.selection.range,2,2);
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;