12-07-2009, 04:08 PM
procedure من أجل تصدير ملف قاعدة بيانات إلى ملف إكسل بطريقة لبقة
كود :
procedure export_Dataset_to_excel(Dataset :tdataset);
var
//procedure permet de transférer les données d'un dataset ver un fichier excel
// fait par Bendib yassine
XLApp : TexcelApplication;
Classeur : _workbook;
feuille: _worksheet;
i,j,cmt: integer;
Formtmp: TForm;
label1,label2 : TLabel;
St: string[100];
begin
Application.CreateForm(TForm, Formtmp);
With formtmp do
begin
Position := poScreenCenter;
BorderStyle := bsToolWindow;
Width := 400;
Height := 70;
Caption := 'Transfère des données encoure... ';
end;
Label1 :=TLabel.Create(nil) ;
with (label1) do
begin
Name := 'label1';
Caption := 'copie l''enregistrement ';
parent := Formtmp;
Align := alTop;
Font.Size := 16;
Font.Style := [Fsbold];
Alignment := taCenter;
end;
Label2 :=TLabel.Create(nil) ;
with (label2) do
begin
Name := 'label2';
Caption := 'Veuillez Patientez SVP ';
parent := Formtmp;
Align := alBottom;
Font.Size := 12;
Font.Style := [Fsbold];
Font.Color := clred;
Alignment := taCenter;
end;
formtmp.Show;
//--
XLApp := TExcelApplication.Create(Application);
Xlapp.Connect;
Classeur:=XlApp.Workbooks.Add(EmptyParam,0);
Feuille:=Classeur.Worksheets[1] as _worksheet;
// feuille.DisplayRightToLeft[1]:=1; ///activier cette ligne si vous utliser une table contient des données en arabe
Dataset.DisableControls;
Dataset.First;
cmt := 1;
for j := 0 to dataset.FieldCount-1 do
begin
st :=dataset.fields[j].DisplayName;
st :=StringReplace (trim(st),'_',' ',[rfReplaceAll]);
Feuille.Cells.Item[1,1+j].value:= st;
end;
i:=0;
while not dataset.Eof do
begin
for j := 0 to dataset.FieldCount-1 do
Feuille.Cells.Item[2+i,1+j].value:=dataset.fields[j].AsString ;
label1.Caption := 'copie l''enregistrement '+inttostr(cmt) + '/'+inttostr(dataset.recordcount);
Formtmp.Update;
dataset.next;
cmt:= cmt+1;
i:=i+1;
end;
Dataset.EnableControls;
//--
Formtmp.Close;
Formtmp.free;
ShowMessage ('Terminé...');
XLApp.Visible[1]:=true ;
XLApp.Disconnect;
XLApp.free;
end;