使用DBGridEh怎样导出Excel?(50分)

  • 主题发起人 主题发起人 seasky212
  • 开始时间 开始时间
S

seasky212

Unregistered / Unconfirmed
GUEST, unregistred user!
看了很多帖子,有种说法是:“
用dbgrideh,有个函数可直接,SaveDBGridEhToExportFile(TDBGridEhExportAsXLS,dbgrideh1,'c:/xx.xls',true)可
以可存dbgrideh的内容到excel中,要use DBGridEhImpExp”

"SaveDBGridEhToExportFile"怎么无法编译?
是DBGridEh的一个方法吗?
谢谢!
 
先要uses DBGridEhImpExp

function DBGExport(var dbg: TDBGridEh): boolean;
var
fd_file: TSaveDialog;
fn: string;
sa: boolean;
begin
result := true;

fd_file := TSaveDialog.Create(Application);
try
fd_file.DefaultExt := 'xls';
fd_file.Filter := 'Microsoft Excel 文件(*.xls)|*.XLS|文本文件(*.txt)|*.TXT|Csv文件(*.csv)|*.Csv|HTML文件(*.htm)|*.htm|RTF文件(*.rtf)|*.RTF';

if (not dbg.DataSource.DataSet.Active) or (not fd_file.Execute) then
begin
result := False;
Exit;
end;
fn := fd_file.filename;

sa := (dbg.Selection.SelectionType = gstNon);
case fd_file.FilterIndex of
2: SaveDBGridEhToExportFile(TDBGridEhExportAsText, dbg, fn, sa);
3: SaveDBGridEhToExportFile(TDBGridEhExportAsCsv, dbg, fn, sa);
4: SaveDBGridEhToExportFile(TDBGridEhExportAsHTML, dbg, fn, sa);
5: SaveDBGridEhToExportFile(TDBGridEhExportAsRTF, dbg, fn, sa);
else
SaveDBGridEhToExportFile(TDBGridEhExportAsXLS, dbg, fn, sa);
end;
finally
fd_file.Free;
end;
end;
 
在DbGridEh目录下有一个工具单元:DBGridEhImpExp.pas

引用就可以了

里面还有其他方法:
——————————————————————————
{ Routines to import/export DBGridEh to/from file/stream }

procedure SaveDBGridEhToExportFile(ExportClass: TDBGridEhExportClass;
DBGridEh: TCustomDBGridEh; const FileName: String; IsSaveAll: Boolean);
procedure WriteDBGridEhToExportStream(ExportClass: TDBGridEhExportClass;
DBGridEh: TCustomDBGridEh; Stream: TStream; IsSaveAll: Boolean);

procedure LoadDBGridEhFromImportFile(ImportClass: TDBGridEhImportClass;
DBGridEh: TCustomDBGridEh; const FileName: String; IsLoadToAll: Boolean);
procedure ReadDBGridEhFromImportStream(ImportClass: TDBGridEhImportClass;
DBGridEh: TCustomDBGridEh; Stream: TStream; IsLoadToAll: Boolean);
 
他的DEMO中有呀
 
to luck_99:
我用的是EhLib.v3.5.Full.Source.For.Delphi.BCB的版本的。demos
中只有两个没有看到了。你用的是哪个版本?可以给我发一下吗?
season_k2005@163.com

谢谢!
 
多人接受答案了。
 
后退
顶部