Exporter

krangrion Messages postés 1 Date d'inscription mercredi 23 février 2005 Statut Membre Dernière intervention 21 novembre 2005 - 21 nov. 2005 à 13:14
jpleroisse Messages postés 1788 Date d'inscription mardi 7 novembre 2000 Statut Membre Dernière intervention 11 mars 2006 - 21 nov. 2005 à 15:09
Peut ton exporter un datagrid vers excel ? Si oui comment on fait ?

Kiki

1 réponse

jpleroisse Messages postés 1788 Date d'inscription mardi 7 novembre 2000 Statut Membre Dernière intervention 11 mars 2006 27
21 nov. 2005 à 15:09
Bonjour,

Dans Projet/Références, tu coches Microsoft Excel x.0
Object Library Ensuite tu places ce code(Si tu as donnés des noms à tes
contrôles ADODC et DataGrid, change le code en fonction de celà).



Private Sub Command1_Click()

Dim i, j

Dim Ex As New Excel.Application 'Declaration

Set Ex = New Excel.Application 'Initialisation de l'objet

Ex.Workbooks.Add 'nouveau classeur,Ex.Workbooks.Add "Nom du fichier excel"'Ouverture d'un fichier excel existant



Adodc1.Refresh

Ex.Cells(2, 1) = "Société"

Ex.Cells(2, 2) = "Commande"

Ex.Cells(2, 3) = "Date Livraison"

Ex.Cells(2, 4) = "Montant TTC"

j = 3

While Not Adodc1.Recordset.EOF

For i = 0 To 3

Ex.Cells(j, i + 1) = DataGrid1.Columns(i)

Next

Adodc1.Recordset.MoveNext

j = j + 1

Wend

Ex.Visible = True



End Sub



jpleroisse



Si une réponse vous convient, cliquez Réponse Acceptée.
0
Rejoignez-nous