opendialog1.Execute; opendialog1.Filter :='*.doc';{如果是打开了的文档就通过对话框选择它} filename:=opendialog1.FileName ; //extractfilepath(paramstr(0))+'\用户合同\用户合同模板.doc'; msword:=createoleobject('word.application'); try msword.visible:=true; if not fileexists(filename) then begin showmessage('该模板文件不存在请添加'); msword.quit; end else begin msword.documents.open(filename,true,true); msword.doucuments.items.text:='aaabbb'{你想要加入的字符串} end; except msword.quit; abort; end;
sendmessage('wordhandle',wm_paste,0,0)
Wordapplication1.Connect;
Wordapplication1.Visible := false;
vDoc:=Wordapplication1.Documents.Add(????);
vDoc.Range.InsertAfter('qqq');
opendialog1.Filter :='*.doc';{如果是打开了的文档就通过对话框选择它}
filename:=opendialog1.FileName ; //extractfilepath(paramstr(0))+'\用户合同\用户合同模板.doc';
msword:=createoleobject('word.application');
try
msword.visible:=true;
if not fileexists(filename) then
begin
showmessage('该模板文件不存在请添加');
msword.quit;
end
else
begin
msword.documents.open(filename,true,true);
msword.doucuments.items.text:='aaabbb'{你想要加入的字符串}
end;
except
msword.quit;
abort;
end;
vDoc.Close(True);
vWord.Quit(true);
Wordapplication1.Quit;
Wordapplication1.Disconnect;
后,总会自动打开一个word窗口,然后不能完全关闭,不像调用Excel那样,完全后台调用。
var
wordapp,doc,rag:variant;
begin
try
wordapp:=createoleobject('word.application');
wordapp.visible:=true;
doc:=wordapp.documents.add;
rag:=doc.paragraphs.last.range;
rag.insertafter('test');
doc.saveas('c:\test');
finally
rag:=unassigned;
doc:=unassigned;
wordapp:=unassigned;
end;end;
具体可以参考搜索Google的"Delphi控制(操作)Word"