导出Excel中:
procedure ExportDBGridEh(DBGridEh: TDBGridEh);
var
SaveDialog:TSaveDialog;
ExpClass:TDBGridEhExportClass;
Ext:String;
begin
SaveDialog := TSaveDialog.create(nil);
saveDialog.Filter:='Text files (*.txt)|*.TXT|Comma separated values (*.csv)|*' +
'.CSV|HTML file (*.htm)|*.HTM|Rich Text Format (*.rtf)|*.RTF|Microsoft Excel ' +
'Workbook (*.xls)|*.XLS ';
if SaveDialog.Execute then
begin
case SaveDialog.FilterIndex of
1: begin
ExpClass := TDBGridEhExportAsText;
Ext := 'txt';
end;
2: begin
ExpClass := TDBGridEhExportAsCSV;
Ext := 'csv';
end;
3: begin
ExpClass := TDBGridEhExportAsHTML;
Ext := 'htm';
end;
4: begin
ExpClass := TDBGridEhExportAsRTF;
Ext := 'rtf';
end;
5: begin
ExpClass := TDBGridEhExportAsXLS;
Ext := 'xls';
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,DBGridEh,
SaveDialog.FileName,true);
end;
end;
end;