Exportation DBgrid vers EXcel

cs_MohInfo Messages postés 58 Date d'inscription mardi 24 avril 2007 Statut Membre Dernière intervention 14 juin 2011 - 15 févr. 2011 à 11:45
Nssm979804 Messages postés 2 Date d'inscription mardi 3 juin 2014 Statut Membre Dernière intervention 3 juin 2014 - 3 juin 2014 à 21:16
bonjour à tous

je veux exporter mon dbgrid vers MSExcel, bon j'ai réussi de faire ça dans une seule feiulle Excel mais j'arrive pas à exporter dans différentes feuilles excel selon un critér donné

par exemple :
je fais une requets SQL sur une table ado PUIS j'exporte le contenu de DBGrid qui correspond à la requete dans une feuille EXcel et ainsi de suite (chaque critére de la requete SQl sera affiché dans une feuille Excel)

merci pour votre aide

4 réponses

tiaret2005 Messages postés 3 Date d'inscription mardi 21 novembre 2006 Statut Membre Dernière intervention 3 août 2013
15 févr. 2011 à 20:52
meri
0
cs_MohInfo Messages postés 58 Date d'inscription mardi 24 avril 2007 Statut Membre Dernière intervention 14 juin 2011
16 févr. 2011 à 18:59
bonsoir
j'ai pas compris votre réponse monsieur tiaret 2005

l'essentiel moi j'ai réussi d'exporter la DBGrid vers excel avec le composant TJVExelExport (exportation simple )mais j'arrive pas à faire cette procédure dans différentes feuilles excel

merci pour votre aide
0
giorhof Messages postés 18 Date d'inscription samedi 2 août 2008 Statut Membre Dernière intervention 5 décembre 2020
11 nov. 2011 à 17:48
Bonsoir
Mohinfo, Etant un débutant dans la programmation, pourriez vous me décrire comment paramétrer le TJVExelExport pour générer le fichier excel avec les données dans la base?
merci d'avance
giorhof
0
laoubiadel Messages postés 9 Date d'inscription jeudi 26 février 2009 Statut Membre Dernière intervention 16 mai 2012
16 mai 2012 à 01:42
procedure TForm1.Button2Click(Sender: TObject);
var Tab: _workbook;
Feuil: _worksheet;
i,j:Integer;
S:shortstring;

begin

try
ExcelApplication1.Connect;
ExcelApplication1.Visible[0]:=False;
Tab:=ExcelApplication1.Workbooks.Add(xlWBATWorksheet,0);
ExcelApplication1.Visible[0]:=true;
feuil:=Tab.Worksheets[1] as _worksheet;
case RadioGroup1.ItemIndex of
0:begin
For i:=0 to DBGrid1.Columns.Count-1 do begin
with Feuil.Range[A[i+1]+'1',A[i+1]+'1'] do begin
Value[xlRangeValueDefault]:= DBGrid1.Columns.Items[i].Title.Caption;
Font.Name:='times new roman';
Font.Size:=10;
Font.Bold:=True;
With Interior do begin
ColorIndex := 15;
Pattern := xlSolid;
PatternColorIndex := xlAutomatic;
End;
With Borders do begin
LineStyle := xlContinuous;
Weight := xlThin;
ColorIndex := xlAutomatic;
End;
end;
end;
j:=2;
Table1.First;
While not Table1.Eof do begin
For i:= 1 To DBGrid1.Columns.Count Do begin
s:=A[i]+inttostr(j);
Feuil.Range[s,s].Value[xlRangeValueDefault] :=DBGrid1.Fields[i-1].AsString;
end;
Table1.Next;
j:=j+1;
end;
end;
1: begin
For i:=0 to Table1.FieldCount-1 do begin
with Feuil.Range[A[i+1]+'1',A[i+1]+'1'] do begin
Value[xlRangeValueDefault]:= Table1.Fields.Fields[i].FieldName;
Font.Name:='times new roman';
Font.Size:=10;
Font.Bold:=True;
With Interior do begin
ColorIndex := 15;
Pattern := xlSolid;
PatternColorIndex := xlAutomatic;
End;
With Borders do begin
LineStyle := xlContinuous;
Weight := xlThin;
ColorIndex := xlAutomatic;
End;
end;
end;
j:=2;
Table1.First;
While not Table1.Eof do begin
For i:= 1 To Table1.FieldCount Do
begin
s:=A[i]+inttostr(j);
Feuil.Range[s,s].Value[xlRangeValueDefault] :=Table1.Fields.Fields[i-1].AsString;
end;
Table1.Next;
j:=j+1;
end;
end;
end;
finally
ExcelApplication1.Cells.Select;
ExcelApplication1.Columns.AutoFit;
ExcelApplication1.Range['A1','A1'].Select;
ExcelApplication1.Disconnect;
end;

end;
--------------------------
button pour spécifier la translation dbgrid ver excel
-----------------------------------------
0
Nssm979804 Messages postés 2 Date d'inscription mardi 3 juin 2014 Statut Membre Dernière intervention 3 juin 2014
3 juin 2014 à 21:16
je voudrai savoir si il serait possible de sélectionner des lignes sur un DBGrid et les exporter sous forme de tableau dans un document Excel
0
Rejoignez-nous