将连接Quickreport的Query的数据倒入到excel中
try
if Savedialog2.Execute then
begin
filename :=savedialog2.filename;
MsExcel:=Createoleobject('Excel.application');
msexcel.visible:=false;
// Msexcel.workbooks.Open(filename,false);
Msexcel.workbooks.add;
//end;
for n:=0 to Form1.ADOQuery1.FieldCount-1do
Msexcel.cells[1,n+1].value:=Form1.ADOQuery1.Fields[n].DisplayLabel;
Form1.ADOQuery1.First;
m:=2;
//showmessage(Adoquery1.fieldvalues[1]);
while not Form1.ADOQuery1.Eofdo
begin
for i:=0 to Form1.ADOQuery1.FieldCount-1do
begin
Exc:=Form1.ADOQuery1.Fields.AsString;
Msexcel.cells[m,i+1].value:=Exc;//Adoquery1.FieldByName.AsString;
end;
Form1.ADOQuery1.next;//quotedstr(Adoquery1.FieldValues[1]);
Inc(m);
end;
Msexcel.activeworkbook.saveas(savedialog2.filename);
//Msexcel.activebook.saved:=true;
Msexcel.quit;
Application.MessageBox('导出完毕!','提示',MB_ok or Mb_Iconinformation);
end;
except
on E:Exceptiondo
ShowMessage(E.Message);
end;