procedure TABC.Button1Click(Sender: TObject);
var col:integer;
begin
if abc_adoquery.Active=false then
begin
application.MessageBox('没有查询数据','提示',mb_ok+mb_iconwarning);
exit;
end;
try
button1.Enabled:=false;
ExcelApplication1.Connect;
excelapplication1.Visible[0]:=FALSE;
ExcelWorkbook1.ConnectTo(ExcelApplication1.Workbooks.Add(EmptyParam,0));
ExcelWorkSheet1.ConnectTo(excelworkbook1.Worksheets.Add(emptyparam,emptyparam,emptyparam,emptyparam,0)as _worksheet);
ExcelApplication1.Caption:='XXX';
Excelworksheet1.Cells.Item[1,1]:='XXX';
Excelworksheet1.Range['A1','G1'].MergeCells:=true;
Excelworksheet1.Range['A1','G1'].HorizontalAlignment:=xlcenter;
Excelworksheet1.Range['A1','G1'].VerticalAlignment:=xlcenter;
Excelworksheet1.Range['A1','G1'].MergeCells:=True;
Excelworksheet1.Range['A1','G1'].Font.Name:='宋体';
Excelworksheet1.Range['A1','G1'].Font.Bold:=True;
Excelworksheet1.Range['A1','G1'].Font.Size:=16;
Excelworksheet1.Cells.Item[2,1]:='XXX';
Excelworksheet1.Cells.Item[2,2]:='XXX';
Excelworksheet1.Cells.Item[2,3]:='XXX';
Excelworksheet1.Cells.Item[2,4]:='XXX';
Excelworksheet1.Cells.Item[2,5]:='XXX';
Excelworksheet1.Cells.Item[2,6]:='XXX';
Excelworksheet1.Cells.Item[2,7]:='XXX';
col:=3;
abc_adoquery.First;
while not(abc_adoquery.Eof) do
begin
Excelworksheet1.Cells.Item[col,1]:=abc_adoquery.fieldbyname('XXX').AsString;
Excelworksheet1.Cells.Item[col,2]:=abc_adoquery.fieldbyname('XXX').AsString;
Excelworksheet1.Cells.Item[col,3]:=abc_adoquery.fieldbyname('XXX').AsString;
Excelworksheet1.Cells.Item[col,4]:=abc_adoquery.fieldbyname('XXX').Asfloat;
Excelworksheet1.Cells.Item[col,5]:=abc_adoquery.fieldbyname('XXX').Asstring;
Excelworksheet1.Cells.Item[col,6]:=abc_adoquery.fieldbyname('XXX').asstring;
Excelworksheet1.Cells.Item[col,7]:=abc_adoquery.fieldbyname('XXX').AsString;
col:=col+1;
abc_adoquery.Next;
end;
finally
button1.Enabled:=true;
excelapplication1.Visible[0]:=TRUE;
ExcelWorkSheet1.Disconnect;
ExcelWorkbook1.Disconnect;
ExcelApplication1.Disconnect;
end;
end;