Bonjour à tous,
J'ai fait une application qui me sort un état en quickreport et je voudrais savoir comment exporter cet état en un tableau excel afin de l'arranger un peu avant de l'imprimer.
Merci.
Bonjour à tous,
J'ai fait une application qui me sort un état en quickreport et je voudrais savoir comment exporter cet état en un tableau excel afin de l'arranger un peu avant de l'imprimer.
Merci.
salut
il existe des solution payantes toutes faites mais pour ma part je les ai trouver peut convaincante
le mieux est soit :
- de construire directement le fichier ecxel sans passer par le quickreport .
- dans les evenement afterprint tu definis les donnée que tu veut mettre et la colonne dans laquelle le mettre.
@+ Phil
J’ai une fonction qui envoie dbGrid vers un classeur Excel en construisant le fichier sans ouvrir l’Excel, si tu est Intéressé ?![]()
Bonjour,
Pourquoi tu n'a pas essayé de nous proposé cette fonction?kkhaled a ecrit:
J’ai une fonction qui envoie dbGrid vers un classeur Excel en construisant le fichier sans ouvrir l’Excel, si tu est Intéressé ?
car tous les code proposé dans ce forum sont toujours utiles.
Merci.
Je suis intéressé par les 2 solutions le DBGrid et la construction du fichier excel sans passer par le QuickRep.
Comment procéder ?
Merci à vous.
pour quick repot c'est l'export de données vers un format donc essaye de l'exporter ces données en excel
Utilise l'onglet serveur sur la pallette des composant c'est facile a manipuler
J'ai trouvé ça mais je vois pas comment l'utiliser ?
j'aimerais que quelqu'un me montre juste par où commenser ?
exemple d'export StringGrid
var
xls, wb, Range: OLEVariant;
arrData: Variant;
begin
{creation variant qui contient tes données}
arrData := VarArrayCreate([1, StringGrid.RowCount, 1,
StringGrid.ColCount], varVariant);
for i := 1 to yourStringGrid.RowCount do
for j := 1 to yourStringGrid.ColCount do
arrData[i, j] := yourStringGrid.Cells[j - 1, i - 1];
{initialize une instance de Excel}
xls := CreateOLEObject('Excel.Application');
{create workbook}
wb := xls.Workbooks.Add;
//arranger le fichier excel de façon a ce quil contien les memes colonnes
Range := wb.WorkSheets[1].Range[wb.WorkSheets[1].Cells[1, 1],
wb.WorkSheets[1].Cells[yourStringGrid.RowCount, yourStringGrid.ColCount]];
{copié les données vers variant array}
Range.Value := arrData;
{afficher Excel avec les données}
xls.Visible := True;
end;
Dans la parie Interface
Dans la partie implimentation
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 XLSBOF: array[0..4] of Word = ($409, 6, 0, $10, 0); XLSGUTS: array[0..5] of Word = ($80, 8, 0, 0, 0, 0); XLSPalette: array[0..2] of Word = ($92, 0, 0); XLSDimension: array [0..6] of Word = ($200, $0A, 0, $FFFF, 0, $FF, 0); XLSEOF: array[0..1] of Word = ($0A, 0); XLSFONTH: array[0..9] of Byte = ($31, 2, 0, 0, 0, 0, 0, 0, 8, 0); XLSFONTG: array[0..9] of Byte = ($31, 2, 0, 0, 0, 0, 0, 0, 10, 0); XLSFONT: array[0..9] of Byte = ($31, 2, 0, 0, 0, 0, 0, 0, 0, 0); XLSXF1: array[0..15] of Byte = ($43, 4, $0C, 0, 0, 0, $F5, $FF, $20, 0, 0, $CE, 0, 0, 0, 0); XLSXF2: array[0..15] of Byte = ($43, 4, $0C, 0, 1, 0, $F5, $FF, $20, $F4, 0, $CE, 0, 0, 0, 0); XLSXF3: array[0..15] of Byte = ($43, 4, $0C, 0, 2, 0, $F5, $FF, $20, $F4, 0, $CE, 0, 0, 0, 0); XLSXF4: array[0..15] of Byte = ($43, 4, $0C, 0, 0, 0, $F5, $FF, $20, $F4, 0, $CE, 0, 0, 0, 0); XLSXF5: array[0..15] of Byte = ($43, 4, $0C, 0, 0, 0, 1, 0, $20, 0, 0, $CE, 0, 0, 0, 0); XLSXF6: array[0..15] of Byte = ($43, 4, $0C, 0, 1, $21, $F5, $FF, $20, $F8, 0, $CE, 0, 0, 0, 0); XLSXF7: array[0..15] of Byte = ($43, 4, $0C, 0, 1, $1F, $F5, $FF, $20, $F8, 0, $CE, 0, 0, 0, 0); XLSXF8: array[0..15] of Byte = ($43, 4, $0C, 0, 1, $20, $F5, $FF, $20, $F8, 0, $CE, 0, 0, 0, 0); XLSXF9: array[0..15] of Byte = ($43, 4, $0C, 0, 1, $1E, $F5, $FF, $20, $F8, 0, $CE, 0, 0, 0, 0); XLSXF10: array[0..15] of Byte = ($43, 4, $0C, 0, 1, $0D, $F5, $FF, $20, $F8, 0, $CE, 0, 0, 0, 0); XLSXF: array[0..15] of Byte = ($43, 4, $0C, 0, 5, 0, 1, 0, $21, $78, $41, 3, 0, 0, 0, 0); XLSXFB: array[0..15] of Byte = ($43, 4, $0C, 0, 8, 0, 1, 0, $22, $78, $41, 2, $71, $71, $71, 0); XLSXFH: array[0..15] of Byte = ($43, 4, $0C, 0, 6, 0, 1, 0, $22, $78, $41, 2, $71, $71, $71, $71); XLSXFG: array[0..15] of Byte = ($43, 4, $0C, 0, 7, 0, 1, 0, $21, $78, $C1, 2, 0, 0, 0, 0); XLSXFF: array[0..15] of Byte = ($43, 4, $0C, 0, 5, 0, 1, 0, $22, $78, $C1, 2, $B9, $B9, $B9, $B9); XLSXFF1: array[0..15] of Byte = ($43, 4, $0C, 0, 5, 0, 1, 0, $22, $78, $C1, 2, $B9, 0, $B9, 0); XLSXFRF: array[0..15] of Byte = ($43, 4, $0C, 0, 9, 0, 1, 0, $21, $78, $C1, 2, $B9, $B9, $B9, $B9); XLSXFRF1: array[0..15] of Byte = ($43, 4, $0C, 0, 9, 0, 1, 0, $21, $78, $C1, 2, $B9, 0, $B9, 0); XLSCOL: array[0..7] of Word = ($7D, $0C, 0, 0, 0, $F, 0, 0); XLSSFONT: array[0..15] of Byte = ($31, 2, $0C, 0, $C8, 0, 0, 0, $FF, $7F, 5, $41, $72, $69, $61, $6C); XLSLabel: array[0..5] of Word = ($204, 0, 0, 0, 0, 0); XLSBlank: array[0..4] of Word = ($201, 6, 0, 0, $17); XLSBlankF: array[0..4] of Word = ($201, 6, 0, 0, $19); XLSBlankRF: array[0..4] of Word = ($201, 6, 0, 0, $1C); XLSNumber: array[0..4] of Word = ($203, 14, 0, 0, 0); XLSRK: array[0..4] of Word = ($27E, 10, 0, 0, 0); XLSFormula: array[0..15] of Word =($406, $1D, 0, 0, $18, 0, 0, 0, 0, 3, $0B, $25, 0, 0, 0, 0);
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197 procedure TForm1.SaveGridToXls(grid: TDBGrid; FileName: String); var C: LongInt; S: string; B: Byte; i, j, k, l : Integer; HeaderColor : TColor; HeaderFontColor : TColor ; FontColor : TColor; Couleur : Tcolor; GridLineColor : TColor; Dir : String; MonClasseur : _workbook; MaFeuille :_Worksheet; Stream : TFileStream; TotalCount : Word; begin HeaderColor := clblue; HeaderFontColor := clred; GridLineColor := cllime; Couleur := clOlive; FontColor := clWhite; TotalCount := 1; dir := ExtractFileDir(Application.ExeName); if Dir[length(Dir)] <>'\' then Dir := Dir+'\'; Dir := Dir+FileName+'.xls'; Stream := TFileStream.Create(Dir, fmCreate); Stream.WriteBuffer(XLSBOF, SizeOf(XLSBOF)); Stream.WriteBuffer(XLSGUTS, SizeOf(XLSGUTS)); // XLS Palette XLSPalette[1] := 22; XLSPalette[2] := 5; Stream.WriteBuffer(XLSPalette, SizeOf(XLSPalette)); if HeaderFontColor = clNone then C := 0 else C := ColorToRGB(HeaderFontColor); Stream.WriteBuffer(C, SizeOf(C)); //1 15 if HeaderColor = clNone then C := 0 else C := ColorToRGB(HeaderColor); Stream.WriteBuffer(C, SizeOf(C)); //2 16 if FontColor = clNone then C := 0 else C := ColorToRGB(FontColor); Stream.WriteBuffer(C, SizeOf(C)); //3 17 if Couleur = clNone then C := 0 else C := ColorToRGB(Couleur); Stream.WriteBuffer(C, SizeOf(C)); //4 18 if GridLineColor = clNone then C := 0 else C := ColorToRGB(GridLineColor); Stream.WriteBuffer(C, SizeOf(C)); //5 19 // XLS Font Stream.WriteBuffer(XLSSFont, SizeOf(XLSSFont)); Stream.WriteBuffer(XLSSFont, SizeOf(XLSSFont)); Stream.WriteBuffer(XLSSFont, SizeOf(XLSSFont)); Stream.WriteBuffer(XLSSFont, SizeOf(XLSSFont)); // Grid Font S := 'MS Sans Serif'; B := Length(S); XLSFont[2] := B + 7; XLSFont[4] := 8*20 mod 256; XLSFont[5] := 8*20 div 256; XLSFont[6] := 2; XLSFont[8] := 10; Stream.WriteBuffer(XLSFont, SizeOf(XLSFont)); Stream.WriteBuffer(B, SizeOf(B)); Stream.WriteBuffer(Pointer(S)^, Length(S)); // Header Font S := 'MS Sans Serif'; B := Length(S); XLSFontH[2] := B + 7; XLSFontH[4] := 8*20 mod 256; XLSFontH[5] := 8*20 div 256; XLSFontH[6] := 0; Stream.WriteBuffer(XLSFontH, SizeOf(XLSFontH)); Stream.WriteBuffer(B, SizeOf(B)); Stream.WriteBuffer(Pointer(S)^, Length(S)); // Columns Fonts i := -1; for l := 0 to Grid.Columns.Count - 1 do if Grid.Columns[l].Visible then begin inc(i); S := 'MS Sans Serif'; B := Length(S); XLSFont[2] := B + 7; XLSFont[4] := 8*20 mod 256; XLSFont[5] := 8*20 div 256; XLSFont[6] := 2; XLSFont[8] := 5; Stream.WriteBuffer(XLSFont, SizeOf(XLSFont)); Stream.WriteBuffer(B, SizeOf(B)); Stream.WriteBuffer(Pointer(S)^, Length(S)); end; // Grid Stream.WriteBuffer(XLSXF1, SizeOf(XLSXF1)); Stream.WriteBuffer(XLSXF2, SizeOf(XLSXF2)); Stream.WriteBuffer(XLSXF2, SizeOf(XLSXF2)); Stream.WriteBuffer(XLSXF3, SizeOf(XLSXF3)); Stream.WriteBuffer(XLSXF3, SizeOf(XLSXF3)); for i := 0 to 9 do Stream.WriteBuffer(XLSXF4, SizeOf(XLSXF4)); Stream.WriteBuffer(XLSXF5, SizeOf(XLSXF5)); Stream.WriteBuffer(XLSXF6, SizeOf(XLSXF6)); Stream.WriteBuffer(XLSXF7, SizeOf(XLSXF7)); Stream.WriteBuffer(XLSXF8, SizeOf(XLSXF8)); Stream.WriteBuffer(XLSXF9, SizeOf(XLSXF9)); Stream.WriteBuffer(XLSXF10, SizeOf(XLSXF10)); begin XLSXF[12] := $A1; XLSXF[13] := $A1; XLSXF[14] := $A1; XLSXF[15] := $A1; end; Stream.WriteBuffer(XLSXF, SizeOf(XLSXF)); Stream.WriteBuffer(XLSXFH, SizeOf(XLSXFH)); Stream.WriteBuffer(XLSXFG, SizeOf(XLSXFG)); Stream.WriteBuffer(XLSXFF, SizeOf(XLSXFF)); Stream.WriteBuffer(XLSXFF1, SizeOf(XLSXFF1)); Stream.WriteBuffer(XLSXFB, SizeOf(XLSXFB)); Stream.WriteBuffer(XLSXFRF, SizeOf(XLSXFRF)); Stream.WriteBuffer(XLSXFRF1, SizeOf(XLSXFRF1)); i := -1; for l := 0 to Grid.Columns.Count - 1 do if Grid.Columns[l].Visible then begin inc(i); XLSXF[4] := i + 10; case Grid.Columns[l].Alignment of taLeftJustify : XLSXF[8] := $21; taRightJustify : XLSXF[8] := $23; taCenter : XLSXF[8] := $22; end; Stream.WriteBuffer(XLSXF, SizeOf(XLSXF)); end; Stream.WriteBuffer(XLSDimension, SizeOf(XLSDimension)); i := -1; for l := 0 to Grid.Columns.Count - 1 do if Grid.Columns[l].Visible then begin inc(i); S := Grid.Columns[L].Title.Caption; XLSLAbel[1] := Length(S) + 8; XLSLabel[2] := TotalCount; XLSLabel[3] := i ; XLSLabel[4] := $16; XLSLabel[5] := Length(S); Stream.WriteBuffer(XLSLabel, SizeOf(XLSLabel)); Stream.WriteBuffer(Pointer(S)^, Length(S)); end; Inc(TotalCount); Grid.DataSource.DataSet.DisableControls; Grid.DataSource.DataSet.first; j := 0; while not Grid.DataSource.DataSet.Eof do Begin i := -1; for L := 0 to Grid.Columns.Count - 1 do if Grid.Columns[L].Visible then begin inc(i); S := Grid.Columns[L].Field.AsString; XLSLAbel[1] := Length(S) + 8; XLSLabel[2] := TotalCount; XLSLabel[3] := I; XLSLabel[4] := $18; XLSLabel[5] := Length(S); Stream.WriteBuffer(XLSLabel, SizeOf(XLSLabel)); Stream.WriteBuffer(Pointer(S)^, Length(S)); end; Inc(TotalCount); Grid.DataSource.DataSet.Next; end; // Stream.Free; Grid.DataSource.DataSet.first; j := 0; Grid.DataSource.DataSet.EnableControls; Stream.WriteBuffer(XLSEOF, SizeOf(XLSEOF)); Stream.Free; Stream := nil; end;![]()
Bonjour,
A titre d'info. sous internet je récupère un certain tableau que je copie
sur une feuille Excel que je "Sauvegarde sous ..." avec l'extension
.xls et ça marche ?
salut.
Bonjour, ça ne marche pas chez moi y a plusieurs erreurs entre autres :
[Erreur] Unit1.pas(40): Identificateur non déclaré : '_workbook'
il n'a pas reconnu le type _workbook
en sachant que j'utilise le Delphi 6.0
qu'est-ce que j'ai oublié ?
Partager