将dbgrid数据导入excell(50分)

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

shevachenko

Unregistered / Unconfirmed
GUEST, unregistred user!
将dbgrid数据导入excell,最好能有详细步骤[:)]
 
function isExcelInstalled: olevariant;
var exls:olevariant;
begin
try
exls:=createoleobject('Excel.application');
except
application.MessageBox('请先安装MICROSOFT EXCEL!','提示',mb_ok+mb_iconinformation);
exit;
end;
result := exls ;
end;

procedure saveAsExcel(dbgrid: TDBGrid; exls:olevariant);
var
fieldNum: integer;
i,j : integer;
sheet: olevariant;
begin

sheet:= exls.workbooks[1].worksheets[1];
with query1 do
begin
DisableControls;
fieldNum := dbgrid.fieldCount;
for i:=1 to fieldNum do
begin
sheet.Cells.Item[1,i]:=Fields[i-1].FieldName;
end;
first;
i:=2;
while not eof do
begin
for j:=1 to fieldNum do
begin
sheet.Cells.Item[i,j]:=fields[j-1].AsString;
end;
next;
inc(i);
end;
EnableControls;
exls.visible:=true;
end;
end;
 
接受答案了.
 
后退
顶部