在ACCESS里建一个OLE字段来保存文件,例: procedure TdlgFile.btnBrowClick(Sender: TObject); var Ext:string;//文件扩展名, TxtFileName:string;//保存文件名 v:Olevariant; begin //if lstFile.ItemIndex<0 then // exit; // 将所有的 // strTitle:=lstFile.Items.Strings[lstFile.itemindex]; // frmData.QryPhoto.First; // frmData.QryPhoto.MoveBy(lstFile.itemindex); Ext:=frmData.qryphoto.fieldbyname('Ext').asstring; //保存的拓展名 TxtFileName:=RUNPATH+'output\'+FILENAME+Ext; //一个临时文件名 TBLOBField(frmData.qryphoto.fieldbyname('Ole')).SaveToFile(TxtFileName);
if (Comparetext(Ext,'.Doc')=0) or (Comparetext(Ext,'.rtf')=0) or (Comparetext(Ext,'.Txt')=0) then begin try try v:=GetActiveOleObject('Word.Application'); except v:=CreateOleObject('Word.Application'); end; v.Documents.Open(TxtFileName); v.Visible:=True; Except Application.MessageBox('没有安装Office!',Pchar(Application.Title),MB_ICONINFORMATION); V.quit; end; end else if Comparetext(Ext,'.Xls')=0 then //Excel begin try V:=GetActiveOleObject('Excel.Application'); except V:=CreateOleObject('Excel.Application'); end; V.WorkBooks.Open(TxtFileName); V.visible:=True; end; end;
procedure TdlgFile.btnBrowClick(Sender: TObject);
var
Ext:string;//文件扩展名,
TxtFileName:string;//保存文件名
v:Olevariant;
begin
//if lstFile.ItemIndex<0 then
// exit; // 将所有的
// strTitle:=lstFile.Items.Strings[lstFile.itemindex];
// frmData.QryPhoto.First;
// frmData.QryPhoto.MoveBy(lstFile.itemindex);
Ext:=frmData.qryphoto.fieldbyname('Ext').asstring; //保存的拓展名
TxtFileName:=RUNPATH+'output\'+FILENAME+Ext; //一个临时文件名
TBLOBField(frmData.qryphoto.fieldbyname('Ole')).SaveToFile(TxtFileName);
if (Comparetext(Ext,'.Doc')=0) or (Comparetext(Ext,'.rtf')=0) or (Comparetext(Ext,'.Txt')=0) then
begin
try
try
v:=GetActiveOleObject('Word.Application');
except
v:=CreateOleObject('Word.Application');
end;
v.Documents.Open(TxtFileName);
v.Visible:=True;
Except
Application.MessageBox('没有安装Office!',Pchar(Application.Title),MB_ICONINFORMATION);
V.quit;
end;
end else if Comparetext(Ext,'.Xls')=0 then //Excel
begin
try
V:=GetActiveOleObject('Excel.Application');
except
V:=CreateOleObject('Excel.Application');
end;
V.WorkBooks.Open(TxtFileName);
V.visible:=True;
end;
end;