unit uExport; interface uses DBGridEhImpExp, DBGridEh, SysUtils, Dialogs, ComObj, ActiveX, Variants, db, FormWait; procedure ExpDbgridEh(grid:TDBGridEh); procedure ImpDbgridEH(Grid:TDBGridEh); implementation //============================================================================== // 增加进度条显示 by cxg 2008-01-05 10:08:09 //============================================================================== procedure ImpDbgridEH(Grid:TDBGridEh); var OpenDialog:TOpenDialog; begin if (not Assigned(grid)) or (not grid.DataSource.DataSet.Active) then exit; OpenDialog:=TOpenDialog.create(nil); try OpenDialog.Filter:='*.HTM|文本文件' OpenDialog.FilterIndex:=1; if OpenDialog.Execute then begin ShowWaitText('请稍候'); LoadDBGridEhFromImportFile(TDBGridEhImportAsText, Grid,OpenDialog.FileName,True); end; finally OpenDialog.Free; ShowWaitText(); end; end; procedure ExpDbgridEh(grid:TDBGridEh); var ExpClass:TDBGridEhExportClass; Ext:String; SaveDialog:TSaveDialog; begin if (not Assigned(grid)) or (not grid.DataSource.DataSet.Active) or (grid.DataSource.DataSet.IsEmpty) then exit; SaveDialog:=TSaveDialog.Create(nil); try SaveDialog.FileName := 'file1'; SaveDialog.Filter:='EXCEL电子表格|*.XLS|HTML网页|*.HTM|文本文件|*.TXT|CSV' +'|*.CSV|RTF富文本|*.RTF'; SaveDialog.FilterIndex:=1; if SaveDialog.Execute then begin ShowWaitText('请稍候'); try case SaveDialog.FilterIndex of 1: begin ExpClass := TDBGridEhExportAsXLS; Ext := 'xls'; end; 2: begin ExpClass := TDBGridEhExportAsHTML; Ext := 'htm'; end; 3: begin ExpClass := TDBGridEhExportAsText; Ext := 'txt'; end; 4: begin ExpClass := TDBGridEhExportAsCSV; Ext := 'csv'; end; 5: begin ExpClass := TDBGridEhExportAsRTF; Ext := 'rtf'; end; else ExpClass := nil; Ext := ''; end; if ExpClass <> nil then begin if UpperCase(Copy(SaveDialog.FileName, Length(SaveDialog.FileName)-2,3))<> UpperCase(Ext) then SaveDialog.FileName := SaveDialog.FileName + '.' + Ext; SaveDBGridEhToExportFile(ExpClass,grid,SaveDialog.FileName,true); end; finally ShowWaitText(); end; end; finally FreeAndNil(SaveDialog); end; end; end.
本文来自博客园,作者:del88,转载请注明原文链接:https://www.cnblogs.com/del88/archive/2013/03/28/2986891.html
浙公网安备 33010602011771号