1 pièce(s) jointe(s)
Exporter en excel sauf que les champs sélectionnés via un DBgrid
bonjour a touts ,
je travaile avec delphi 2.0 et Paradox
j'utilise Dataset et un tableau et je voudrai exporter mon dbgrid sauf que les chmps a selectione vers un ficher excel
j'utilise la biblioteque OleAuto our l'exportation Excel
cette code exporter tous les champs sélectionné ou non sélectionné
elle est en marche :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| procedure TFSaiPFE.ExporterClick(Sender: TObject);
var
ExcelApplication : variant;
Sheet : variant;
column, row : integer;
I,J: Integer ;
begin
try
begin
ExcelApplication := CreateOleObject('Excel.Application');
ExcelApplication.Visible := true;
end;
except
Showmessage('Cannot create an Excel file, make sure that MS Excel is installed on your system');
Application.Terminate;
end;
ExcelApplication.WorkBooks.Add(-4167);
ExcelApplication.WorkBooks[1].WorkSheets[1].Name := 'my data';
Sheet := ExcelApplication.WorkBooks[1].WorkSheets['my data'];
for I:=1 to DBGrid1.DataSource.DataSet.FieldCount do
begin
Sheet.Cells[1,I]:=PFE_List.Fields[I-1].FieldName;
End;
column:=0;
if (DBGrid1.Datasource.Dataset.EOF) then
begin
MessageDlg('Erreur : Votre tableau est vide '
+#10#13+''+DecimalSeparator, mtError, [mbOk], 0);
ExcelApplication.Visible := false;
Application.Terminate;
end
else
begin
DBGrid1.Datasource.Dataset.First;
while not DBGrid1.DataSource.DataSet.EOF do
begin
for row :=0 to DBGrid1.DataSource.DataSet.FieldCount -1 do
begin
Sheet.Cells[column+2,row+1]:=DBGrid1.DataSource.DataSet.Fields[row].Value;
end;
PFE_List.next;
column:=column+1;
end;
end ;
end; |
merci d'avance