uses Vcl.OleAuto
procedure T供应商管理.dxBarLargeButton3Click(Sender: TObject); var SaveDialog: TSaveDialog; path: string; //路径信息 ExcelAPP: Variant;//变体变量 begin SaveDialog := TSaveDialog.Create(nil); path := ''; try with SaveDialog do begin FileName := '供应商信息' + FormatDateTime('YYYYMMDD', NOW()); //默认文件名 Filter := '*.xls|*.xls|*.xlsx|*.xlsx|'; if Execute then begin case SaveDialog.FilterIndex of 1: ExportGridToExcel(SaveDialog.FileName, 供应商基板1.cxGrid4, true, true, true, 'xls'); 2: ExportGridToXLSX(SaveDialog.FileName, 供应商基板1.cxGrid4, true, true, true, 'xlsx'); //2007 end; end; end; finally path := SaveDialog.FileName; SaveDialog.Free; end; if path <> '' then //打开文件 begin ExcelAPP := CreateOleObject('Excel.Application');//创建EXCEL对象 ExcelAPP.Visible := false; ExcelAPP.WorkBooks.Open(path);//用EXCEL的方法打开文件 ExcelAPP.WorkSheets[1].Activate;//文件操作,到这里就跟VBA操作没什么差别了 ExcelAPP.Visible := True;//显示出来 end; end;
标签:SaveDialog,ExcelAPP,end,delphi,cxgrid,EXCEL,path,true From: https://www.cnblogs.com/yoooos/p/17070520.html