salut,
je travaile avec delphi7 et sql server
j'utilise ado pour mes connections et je voudrai exporter mon dbgrid issu d'une requette (ADO) vers excel
merci d'avance :)
Version imprimable
salut,
je travaile avec delphi7 et sql server
j'utilise ado pour mes connections et je voudrai exporter mon dbgrid issu d'une requette (ADO) vers excel
merci d'avance :)
Bonjour,
as tu fais une recherche sur le forum, lu la FAQ, regardé les tutoriels à ta disposition ?
Je suis persuadé que tu y trouveras des éléments de réponse à ta problématique.
Bonjour,
Afficher un TDataset dans MS Excel
( voir http://www.fobec.com/protec/trucs2/e...=479&rub=CBase)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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78 {....} uses DB; {....} private procedure SendToExcel(aDataSet: TDataSet); {....} uses ComObj, ActiveX, Excel2000; // or Excel97 procedure TForm1.SendToExcel(aDataSet: TDataSet); var PreviewToExcel: TExcelApplication; RangeE: Excel2000.Range; //or RangeE: Excel97.Range I, Row: Integer; Bookmark: TBookmarkStr; begin PreviewToExcel := TExcelApplication.Create(Self); PreviewToExcel.Connect; PreviewToExcel.Workbooks.Add(NULL, 0); RangeE := PreviewToExcel.ActiveCell; for I := 0 to aDataSet.Fields.Count - 1 do begin RangeE.Value := aDataSet.Fields[I].DisplayLabel; RangeE := RangeE.Next; end; aDataSet.DisableControls; try Bookmark := aDataSet.Bookmark; try aDataSet.First; Row := 2; while not aDataSet.EOF do begin //Write down Record As Row in msExcel RangeE := PreviewToExcel.Range['A' + IntToStr(Row), 'A' + IntToStr(Row)]; for I := 0 to aDataSet.Fields.Count - 1 do begin RangeE.Value := aDataSet.Fields[I].AsString; RangeE := RangeE.Next; end; aDataSet.Next; Inc(Row); end; finally aDataSet.Bookmark := Bookmark; end; finally aDataSet.EnableControls; end; //Creating Preview from Range A1..ColumnX //Calculating ASCII 64 (Character Before "A") With Dataset FieldsCount //This Method can only handle range A1..Z?, if want to be excel column type //support, exp "AA"/"IV" RangeE := PreviewToExcel.Range['A1', chr(64 + aDataSet.Fields.Count) + IntToStr(Row - 1)]; RangeE.AutoFormat(8, NULL, NULL, NULL, NULL, NULL, NULL); PreviewToExcel.Visible[0] := True; PreviewToExcel.Disconnect; end; // Beispiel: // Example: procedure TForm1.Button1Click(Sender: TObject); begin SendToExcel(Table1); end;
[RESOLU] ?
Tu peut utiliser les composants :exportdbgrid de lincontournable gamme de composants :JVCL