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
|
procedure TForm1.Export1Click(Sender: TObject);
var
XLApp:Variant;
NbLigne:Integer;
begin
if MessageDlg('Confirmez l''exportation du fichier vers excel?',mtConfirmation,[mbOK, mbCancel],0)=mrOk then
begin
Try XLApp:=CreateOleObject('Excel.Application');
except
ShowMessage('Démarrage de Excel impossible');
Exit;
end;
XLApp.Visible:=True;
XLApp.Workbooks.Add;
//Les champs suivants seront exportés
XLApp.Cells[1,1].Value:='Champ1';
XLApp.Cells[1,2].Value:='Champ2';
XLApp.Cells[1,3].Value:='Champ3';
XLApp.Cells[1,3].Value:='Champ4';
XLApp.Cells[1,3].Value:='Champ5';
NbLigne:=3;
with Table1 do
begin
first;
while not(EOF) do
begin
//Remplissage des champs
XLApp.Cells[NbLigne,1].Value := FieldByName(' Champ1').AsString;
XLApp.Cells[NbLigne,2].Value := FieldByName(' Champ2').AsString;
XLApp.Cells[NbLigne,3].Value := FieldByName(' Champ3').AsString;
XLApp.Cells[NbLigne,4].Value := FieldByName(' Champ4').AsString;
XLApp.Cells[NbLigne,5].Value := FieldByName(' Champ5').AsString;
inc (NbLigne);
Next;
end;
end;
end;
end; |
Partager