function OpenWordDocument(const AFileName: String; AControl: TCustomMemo): Boolean; var NewDoc: Variant; V: OleVariant; begin try try V := CreateOleObject('Word.Application');//建立自动化对象 NewDoc :=V.Documents.Open(AFileName); //打开指定文件 NewDoc.Content.Copy; //拷贝到剪贴板 AControl.Lines.Clear; AControl.PasteFromClipboard; //粘贴 NewDoc.Close; //关闭Word文件 finally V.Quit; //释放自动化对象 end; Result := True; except Result := False; end; end;
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); end; except msword.quit; abort; end;
delphi自带的控件论坛的精华区里有好多Excel的,应该差不多的
AControl: TCustomMemo): Boolean;
var
NewDoc: Variant;
V: OleVariant;
begin
try
try
V := CreateOleObject('Word.Application');//建立自动化对象
NewDoc :=V.Documents.Open(AFileName); //打开指定文件
NewDoc.Content.Copy; //拷贝到剪贴板
AControl.Lines.Clear;
AControl.PasteFromClipboard; //粘贴
NewDoc.Close; //关闭Word文件
finally
V.Quit; //释放自动化对象
end;
Result := True;
except
Result := False;
end;
end;
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);
end;
except
msword.quit;
abort;
end;