procedure SaveToExcel(AFile:string);
var
sheet,XLApp,workbook:Variant;
iRow,MaxRow:integer;
begin
screen.Cursor :=TADOTable.Create(nil);
ADOTable.Connectionstring :=FConnstr;
XLApp:=CreateObject('Excep.Application');
workbook:=CreateObject('Excel.Sheet');
XLApp.DisplayAlerts :=false;
XLApp.ScreenUpdating :=false;
XLApp.workbooks.Add;
Workbook :=XLApp.workbooks[1];
sheet :=workbook.worksheets[1];
ADOTable.TableName :='dog';
ADOTable.Open;
//写EXCEL的标题栏
iRow :=1;
sheet.Cells[iRow,1]:='狗号';
sheet.Cells[iRow,2]:='服务卡号';
.
.
.
//写EXCEL的内容
while not ADOTable.Eof do
begin
inc(iRow);
Sheet.Cells[iRow,1]:=ADOTable.FieldByName('dog').AsString;
Sheet.Cells[iRow,1]:=ADOTable.FieldByName('dog').AsString;
.
.
.
ADOTable.Next;
end;
workbook.SaveAs(AFile);
workbook.Close;
if not VarIsEmpty(XLApp) then
begin
XLApp.DisplayAlerts :=False;
XLApp.ScreenUpdateing :=True;
XLApp.Quit;
end;
ADOTable.Free;
Screen.Cursor :=crDefault;
end;