Bonsoir à tous,
pour l'exportation de mon Dataset vers un fichier Excel , j'utilise cette procédure :
avec MonTableau est déclaré comme une variable globale :
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 procedure TFMonEtat.Button3Click(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; For i:=0 to DBGrid1.Columns.Count-1 do begin with Feuil.Range[MonTableau[i+1]+'1',MonTableau[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; xQuery1.First; While not xQuery1.Eof do begin For i:= 1 To DBGrid1.Columns.Count Do begin s := MonTableau[i]+inttostr(j); Feuil.Range[s,s].Value[xlRangeValueDefault] :=DBGrid1.Fields[i-1].AsString; end; xQuery1.Next; j:=j+1; end; finally SUIMsgDlg(' Exportation des données Terminée . ','MyApp',mtInformation,[mbOK],suiMessageDialog1.UIStyle); ExcelApplication1.Visible[0]:=true; ExcelApplication1.Cells.Select; ExcelApplication1.Columns.AutoFit; ExcelApplication1.Range['A1','A1'].Select; ExcelApplication1.Disconnect; end; end;
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2 Var MonTableau : array [1..26]of string[1]=('A','B','C','D','E','F','G','H','I','J','K','L', 'M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
L’exportation s’exécute bien , mais pour des champs de type texte qui ont des valeurs numériques , ils sont considérés comme des champs de type numérique.
même pour la date, elle est inversée ,
c'est-à-dire au lieu du '18/02/2018' j’obtiens '02/18/2018'
Avez-vous une idée SVP ?
Partager