procedure TForm1.Button2Click(Sender: TObject);
var
fieldNum: Integer;
i, j: Integer;
exls, sheet: variant;
begin
try
exls := createoleobject('Excel.application');
sheet := createoleobject('excel.sheet');
except
application.MessageBox('请先安装MICROSOFT EXCEL!', '提示', mb_ok +
mb_iconinformation);
Exit;
end;
sheet := exls.workbooks.add;
with query2do
begin
active:=false;
sql.Clear;
sql.Text:='select xh as 序号,name as 姓名 from queAll';
//这里改成中文名称!!!!!
active:=true;
DisableControls;
fieldNum := fieldcount;
for i := 1 to fieldNumdo
begin
exls.Cells[1, i].value := fields[i - 1].fieldname;
end;
First;
i := 2;
while not Eofdo
begin
for j := 1 to fieldNumdo
begin
exls.Cells[i, j] := fields[j - 1].AsString;
end;
next;
i := i + 1;
end;
EnableControls;
exls.Visible := true;
end;
end;