Advertisement
kepiss

Untitled

Jul 22nd, 2014
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ===================== Thread ====================================================
  2. type
  3.     ThExport =  class(TThread)
  4.       private
  5.         FfQuery : TZQuery;
  6.         FfProgress : TsProgressBar;
  7.         FfGrid : TsDbgrid;
  8.         FaSQL:String;
  9.  
  10.       procedure ExportToExCell;
  11.       protected
  12.         procedure Execute;Override;
  13.       public
  14.  
  15.         Constructor Create(aQry:TZQuery;
  16.                               _sQL:String;
  17.                               aGrid:TsDBGrid;
  18.                               aProgress:TsProgressBar);
  19.         property Query: TZQuery Read FfQuery write FfQuery;
  20.         property grid : TsDBGrid Read FfGrid write FfGrid;
  21.         property aSQL : String Read FaSQL write FaSQL;
  22.         property Progress : TsProgressBar Read FfProgress write FfProgress;
  23.     end;
  24. =====================================================================================
  25.  
  26. ======== Procedure Export Ke Excell ==================================
  27.  
  28. constructor ThExport.Create( aQry: TZQuery; _sQL: String;
  29.   aGrid: TsDBGrid; aProgress: TsProgressBar);
  30. begin
  31.   FfQuery       := aQry;
  32.   FfProgress    := aProgress;
  33.   FaSQL         := _SQL;
  34.   FfGrid        := aGrid;
  35.  
  36.  
  37.   Inherited Create(False);
  38.  
  39. end;
  40.  
  41. procedure ThExport.Execute;
  42. begin
  43.  
  44.   ExportToEXcell;
  45.  
  46. end;
  47.  
  48. procedure ThExport.ExportToExCell;
  49.   var
  50.    XlApp,Xlbook,XLsheet,
  51.    Range,Chat           : Variant;
  52.    Wapp,Word            : Variant;
  53.    i,x                  : Integer;
  54.    sFile                : String;
  55. begin
  56.  
  57.    Xlapp     := CreateOLEObject('Excel.Application');  -------> Errornya kayaknya disini ni.
  58.  
  59.   Xlbook    := Xlapp.WorkBooks.add;
  60.   XlSheet   := XLbook.worksheets.Add;
  61.  
  62.  
  63.   for  i := 0 to FfGrid.FieldCount -1 do
  64.   begin
  65.     XLsheet.Cells[2,i+1].Value := FfGrid.Columns[i].Title.Caption;
  66.   end;
  67.  
  68.   insertBarang.data(FfQuery,FaSQL);
  69.   FQ2.First;
  70.   x:=1;
  71.  
  72.   FfProgress.Max:= FQ2.RecordCount;
  73.   FfProgress.Position:=0;
  74.   while FfQuery.Eof = False do
  75.   begin
  76.     for I := 0  to FFGRid.FieldCount   -1 do
  77.     begin
  78.       XlSheet.Cells[2+x,i+1].value := FFQuery.Fields[i].AsString;
  79.  
  80.     end;
  81.     inc(x);
  82.     FfProgress.Position :=x;
  83.     sleep(50);
  84.     Application.ProcessMessages;
  85.     FQ2.Next;
  86.   end;
  87.  
  88.   if MessageDlg('Tampilkan Data?',mtConfirmation,[Mbyes,MbNo],0)=mrYes then
  89.   begin
  90.     XlApp.Visible := True;
  91.   end else
  92.   begin
  93.     sFile := InputBox('Data Barang','Hasil Export','D:\Databarang.xlsx');
  94.     XLApp.ActiveWorkBook.SaveAs(sFile);
  95.     XlApp.Visible := True;
  96.   end;
  97.  
  98. end;
  99.  
  100. ====================================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement