主题:求DBGridEh导出到Excel最快的方法
duck04551
[专家分:90] 发布于 2007-12-30 16:29:00
求DBGridEh导出到Excel最快的方法,加100分!望兄弟们帮帮忙!
回复列表 (共2个回复)
沙发
lishan200012 [专家分:200] 发布于 2008-01-04 09:59:00
代码如下:
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, ADODB, ComCtrls, Grids,excelxp, DBGrids, StdCtrls, ExtCtrls,comobj;
type
……
private
{ Private declarations }
public
{ Public declarations }
end;
var
DlgAcc002Form: TDlgAcc002Form;
implementation
{$R *.dfm}
procedure TDlgAcc002Form.Button3Click(Sender: TObject);
var
x,y,i,j:integer;
MsExcel:OleVariant;
begin
try
MSExcel:=CreateOleObject('Excel.Application');
MSExcel.application.Visible:=False;
Except
on Exception do raise exception.Create('无法打开xls文件,请确认已经安装了EXCEL');
end;
MSEXCEL.WORKBOOKS.ADD;
x:=adoquery1.fieldcount;
y:=adoquery1.recordcount;
for I:=1 to x do
MSExcel.cells.item[1,i]:=adoquery1.fields[i-1].fullname;
adoquery1.first;
for j:=2 to y+1 do
begin
for i:=1 to x do
begin
MSExcel.cells.item[j,i]:=adoquery1.fields[i-1].value;
end;
adoquery1.next;
end;
MSExcel.application.Visible:=True;
MSExcel.Quit;
MSExcel:=Unassigned;
Screen.cursor:=crdefault;
end;
板凳
linjipeng0 [专家分:220] 发布于 2008-08-22 14:28:00
uses DBGridEhImpExp
procedure TForm4.SeSkinButton5Click(Sender: TObject);
begin
SaveDialog1.Execute;
if trim(SaveDialog1.FileName)<>'' then
begin
SaveDBGridEhToExportFile(TDBGridEhExportAsText,DBGridEh1, SaveDialog1.FileName,true);
end;
end;
我来回复