procedure TMainForm.ToolButton1Click(Sender: TObject);
var
i,j:integer;
msexcel
levariant;
wbook,wsheet
levariant;
begin
if table_adoquery1.Active=false then
showmessage('没有选中所要打印的数据库')
else
begin
MsExcel:= CreateOleObject('Excel.Application');
WBook:=MsExcel.Application;
wbook.workbooks.add;
WBook.Visible:=True;
WSheet:=WBook.ActiveSheet;
table_ADOQuery1.First;
for j:=1 to SeSkinDBGrid1.FieldCount do
begin
wsheet.cells[1,j]:=SeSkinDBGrid1.Columns[j-1].FieldName
end;//for j
for i:=1 to table_ADOQuery1.RecordCount do
begin
for j:=1 to SeSkinDBGrid1.FieldCount do
begin
wsheet.cells[i+1,j]:=SeSkinDBGrid1.Fields[j-1].AsString;
end;//for j
table_ADOQuery1.Next;
end;//for i
end;//else
end;
ComObj//加在头文件