فاكشن تصدير للاكسل ، كيف احدد سجلات معينه للتصدير
#1
اخواني الكرام انا استخدم الفانكشن التالي للتصدير للاكسل وهو يعمل بكفاءة لكن يقوم بتصدير كل السجلات الموجوده هل فيه طريقة لتصدير سجلات معينة فقط.

الكود:
PHP كود :
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
    // E-mail: Yassine34@*******.com

    
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 := 'شاشة تصدير البيانات للاكسل';
     
end;

     
Label1 :=TLabel.Create(nil) ;
     
with (label1) do
     
begin
          Name 
:= 'label1';
          
Caption := 'اجمالي السجلات المصدرة ';
          
parent := Formtmp;
          
Align := alTop;
          
Font.Size  := 16;
          
Font.Style := [Fsbold];
          
Alignment := taCenter;
     
end;

     
Label2 :=TLabel.Create(nil) ;
     
with (label2) do
     
begin
          Name 
:= 'label2';
          
Caption := 'لحظات من فضلك جاري التصدير....؟ ';
          
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(EmptyStr,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 := ' السجلات التي يتم تصديرها '+inttostr(cmt) + '/'+inttostr(dataset.recordcount);

           
Formtmp.Update;
           
dataset.next;
           
cmt:= cmt+1;
           
i:=i+1;

     
end;
     
Dataset.EnableControls;
      
//--
     
Formtmp.Close;
     
Formtmp.free;
     
ShowMessage ('انتهت العملية بنجاح ....؟');
     
XLApp.Visible[1]:=true ;
     
XLApp.Disconnect;
     
XLApp.free;
end; 

تحياتي وتقديري.
الرد


الردود في هذا الموضوع
فاكشن تصدير للاكسل ، كيف احدد سجلات معينه للتصدير - بواسطة ابومهند - 18-05-2012, 04:41 PM

التنقل السريع :


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم