function ToExcel():boolean;
var
y :integer;
tsList :TStringList;
s :string;
aSheet :Variant;
begin
result:=true;
Excel.Connect; // 打开Excel
Excel.Visible[0]:=true; // 显示Excel
Excel.Workbooks.Add(xlWBATWorksheet,0);
aSheet:=excel.Worksheets.Item[1];
tsList:=TStringList.Create;
try
try
with qryMaster do
begin
Open;
First;
While Not Eof do
begin
s:='';
for y:=0 to FieldCount-1 do
begin
s:=s+Fields[y].AsString+#9;
Application.ProcessMessages;
end;
tsList.Add(s);
// 从表
if qryDetail<>nil then
begin
with qryDetail do
begin
Open;
First;
while Not Eof do
begin
s:='';
for y:=0 to FieldCount-1 do
begin
s:=s+Fields[y].AsString+#9;
Application.ProcessMessages;
end;
tsList.Add(s);
next;
end;
end;
end;
next;
end;
Close;
end;
Clipboard.AsText:=tsList.Text;
except
result:=false;
end;
finally
tsList.Free;
end;
Excel.Disconnect;
aSheet.Paste;
MessageBox(Application.Handle,'数据导出完毕!','系统提示',MB_ICONINFORMATION or MB_OK);
end;