procedure TFrmQuery.DBGrid1CellClick(Column: TColumn);begin//EXP.DExport;end;procedure TFrmQuery.Button3Click(Sender: TObject);beginend;//导出数据procedure TFrmQuery.ExportDATA(Query:TADOQuery);varExcelApp:TExcelApplication;ExcelWKBook:TExcelWorkbook;ExcelWKSheet:TExcelWorksheet;I,J,K:integer;begin if Query.IsEmpty then begin MessageDLG(#13+'无任何数据源可供导出!数据导出操作将中止!',MtError,[MbOk],0); Exit; end;TRYExcelApp:= TExcelApplication.Create(Application);//创建Excel应用ExcelWKBook:= TExcelWorkbook.Create(Application); //创建Excel工作薄ExcelWKSheet:= TExcelWorksheet.Create(Application); //创建Excel工作表ExcelApp.Connect;ExcelApp.Visible[0]:=false;Application.BringToFront; //程序前置EXCEPTMessageDlg('Excel没有安装或创建Excel时出现问题!',mtERROR,[mbYes],0);abort;END;ExcelApp.Workbooks.Add(EmptyParam,0);ExcelWKBook.ConnectTo(ExcelApp.Workbooks[1]);ExcelWKSheet.ConnectTo(ExcelWKBook.Worksheets[1] as _WorkSheet);TRYbeginif SaveDialog1.Execute thenlab.Caption:='正在导出数据,请稍侯......';with Query dobegin for i:=0 to FieldCount-1 do begin ExcelWksheet.Cells.Item[1,i+1]:=Fields.DisplayLabel; end; First; for i := 0 to recordcount - 1 do begin k:=1; for j:=0 to FieldCount-1 do begin if Fields[j].Visible then begin ExcelWksheet.Cells.Item[i+2,k]:=fields[j].AsString; inc(k); end; end; probar.Percent:=Trunc(I /(recordcount-1)*100); lab.Caption:='正在导出数据,请稍侯......'; frmquery.Repaint; next; end;end;ExcelWksheet.SaveAs(SaveDialog1.FileName);END;FinallyExcelWkbook.Save;ExcelApp.Disconnect;ExcelWksheet.Free;ExcelWkbook.Close;ExcelWkbook.Free;ExcelApp.Quit;ExcelApp.Free;end;showmessage('已将表格中的数据成功导出!');end;