Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ===================== Thread ====================================================
- type
- ThExport = class(TThread)
- private
- FfQuery : TZQuery;
- FfProgress : TsProgressBar;
- FfGrid : TsDbgrid;
- FaSQL:String;
- procedure ExportToExCell;
- protected
- procedure Execute;Override;
- public
- Constructor Create(aQry:TZQuery;
- _sQL:String;
- aGrid:TsDBGrid;
- aProgress:TsProgressBar);
- property Query: TZQuery Read FfQuery write FfQuery;
- property grid : TsDBGrid Read FfGrid write FfGrid;
- property aSQL : String Read FaSQL write FaSQL;
- property Progress : TsProgressBar Read FfProgress write FfProgress;
- end;
- =====================================================================================
- ======== Procedure Export Ke Excell ==================================
- constructor ThExport.Create( aQry: TZQuery; _sQL: String;
- aGrid: TsDBGrid; aProgress: TsProgressBar);
- begin
- FfQuery := aQry;
- FfProgress := aProgress;
- FaSQL := _SQL;
- FfGrid := aGrid;
- Inherited Create(False);
- end;
- procedure ThExport.Execute;
- begin
- ExportToEXcell;
- end;
- procedure ThExport.ExportToExCell;
- var
- XlApp,Xlbook,XLsheet,
- Range,Chat : Variant;
- Wapp,Word : Variant;
- i,x : Integer;
- sFile : String;
- begin
- Xlapp := CreateOLEObject('Excel.Application'); -------> Errornya kayaknya disini ni.
- Xlbook := Xlapp.WorkBooks.add;
- XlSheet := XLbook.worksheets.Add;
- for i := 0 to FfGrid.FieldCount -1 do
- begin
- XLsheet.Cells[2,i+1].Value := FfGrid.Columns[i].Title.Caption;
- end;
- insertBarang.data(FfQuery,FaSQL);
- FQ2.First;
- x:=1;
- FfProgress.Max:= FQ2.RecordCount;
- FfProgress.Position:=0;
- while FfQuery.Eof = False do
- begin
- for I := 0 to FFGRid.FieldCount -1 do
- begin
- XlSheet.Cells[2+x,i+1].value := FFQuery.Fields[i].AsString;
- end;
- inc(x);
- FfProgress.Position :=x;
- sleep(50);
- Application.ProcessMessages;
- FQ2.Next;
- end;
- if MessageDlg('Tampilkan Data?',mtConfirmation,[Mbyes,MbNo],0)=mrYes then
- begin
- XlApp.Visible := True;
- end else
- begin
- sFile := InputBox('Data Barang','Hasil Export','D:\Databarang.xlsx');
- XLApp.ActiveWorkBook.SaveAs(sFile);
- XlApp.Visible := True;
- end;
- end;
- ====================================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement