procedure Tfw_prn.Button1Click(Sender: TObject);
var i,j:integer;
begin
bk.Disconnect; //用于将EXCEL与DELPHI断开 bk:Texcelworkbook
sheet.Disconnect; //sheet: TExcelWorksheet;
ExcelApplication.Disconnect;//ExcelApplication1: TExcelApplication;
//将button按钮置为禁止
button1.Enabled:=false;
ExcelApplication.Connect;
bk.ConnectTo(ExcelApplication.Workbooks.Add(xlWBATWorksheet,0));
sheet.ConnectTo( bk.Worksheets[1] as _worksheet);
i:=1;
for j:=1 to 5 do
sheet.cells.item[i,j]:=adotable1.fields[j-1].fieldname;
i:=i+1;
//用于控制过程
adotable1.DisableControls;
adotable1.First;
while not adotable1.eof do
begin
for j:=1 to 5 do
sheet.cells.Item[i,j]:=adotable1.Fields[j-1].AsString; //填写记录
sheet.cells.Item[i,j]:=chr(13);//回车
adotable1.next;
i:=i+1;
end;
adotable1.EnableControls;
ExcelApplication.Visible[0] :=true;
bk.Disconnect;
sheet.Disconnect;
ExcelApplication.Disconnect;
//按钮放开
button1.Enabled:=true;
end;