procedure TForm1.Button1Click(Sender: TObject);
var
i,j: integer;
begin
If MessageDlg( 'ÕæµÄÒªµ¼µ½ExcelÂð£¿',mtConfirmation,[mbYes,mbNo],0) <>IDYES then
begin
Exit;
end;
ExcelApplication1.Connect;
ExcelApplication1.Visible[0]:=True;
Try
ExcelWorkbook1.ConnectTo(ExcelApplication1.Workbooks.Add(EmptyParam,0));
ExcelWorkSheet1.ConnectTo(ExcelApplication1.Worksheets[1] as _WorkSheet);
Except
ShowMessage('Failure');
End;
j:=1;
with ADOQuery1 do
begin
adoquery1.Open;
First;
while not Eof do
begin
for i := 1 to FieldCount do
begin
ExcelWorkSheet1.Cells.Item[j,i]:=Fields[i-1].AsString;
end;
inc(j);
next;
end;
end;
ADOQuery1.First;
//ADOQuery1.Close;
end;
end.
var
i,j: integer;
begin
If MessageDlg( 'ÕæµÄÒªµ¼µ½ExcelÂð£¿',mtConfirmation,[mbYes,mbNo],0) <>IDYES then
begin
Exit;
end;
ExcelApplication1.Connect;
ExcelApplication1.Visible[0]:=True;
Try
ExcelWorkbook1.ConnectTo(ExcelApplication1.Workbooks.Add(EmptyParam,0));
ExcelWorkSheet1.ConnectTo(ExcelApplication1.Worksheets[1] as _WorkSheet);
Except
ShowMessage('Failure');
End;
j:=1;
with ADOQuery1 do
begin
adoquery1.Open;
First;
while not Eof do
begin
for i := 1 to FieldCount do
begin
ExcelWorkSheet1.Cells.Item[j,i]:=Fields[i-1].AsString;
end;
inc(j);
next;
end;
end;
ADOQuery1.First;
//ADOQuery1.Close;
end;
end.
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货