Exporter un datagrid View dans excel

xtremboxman Messages postés 4 Date d'inscription mercredi 9 janvier 2008 Statut Membre Dernière intervention 16 janvier 2008 - 15 janv. 2008 à 10:28
xtremboxman Messages postés 4 Date d'inscription mercredi 9 janvier 2008 Statut Membre Dernière intervention 16 janvier 2008 - 16 janv. 2008 à 08:06
Bonjour
Dans le cadre de mon stage de BTS IG je doit faire un programe VB pour la gestion de l'inventaire annuel d'une entreprise.
Pour ce fair ej'ai besoin d' exporter le resultat final dansexcel afin que celuis-ci puisse être imprimé.
Mon affichage se fait sur un Datagridview.
J'aurais donc voulu exporter sont contenu sous un fichier excel.
J'ai beau chercher sur internet je n'arrive pas à trouver un code qui corresponde à ce que je veut faire ou je ne le comprend pas trés bien.

Voici mon code:
------------------------------------------------------------------------------

'DEBUT

'{Verification que toutes les données necessaires sont definies}

If TypeMatDesc <>
""
And AnneeDesc <>
""
Then

'{Se connecter à la base de donnée}connex.ConnectionString =

"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
"C:\Documents and Settings\XXX\Bureau\Guillaume\GestionMatieresPremieres\GestionMatieresPremieres\GestionStock.mdb"connex.Open()
'{Requette SQL pour comper le nombre de participants}ReqListMat "SELECT [MATIERES TYPE].MatTypeDesc, [NOMBRE MATIERES].MatNombre, MATIERES.MatDesc, [LONGUEUR MATIERES].Longueur, MATIERES.MatPoids, [PRIX UHT MATIERES].MatPrixUHT FROM (([MATIERES TYPE] INNER JOIN (MATIERES INNER JOIN (ANNEE INNER JOIN [LONGUEUR MATIERES] ON ANNEE.AnneeCode [LONGUEUR MATIERES].AnneeCode)"ON MATIERES.MatCode = [LONGUEUR MATIERES].MatCode) ON [MATIERES TYPE].MatTypeCode = MATIERES.MatTypeCode) INNER JOIN [NOMBRE MATIERES] ON (MATIERES.MatCode = [NOMBRE MATIERES].MatCode) AND (ANNEE.AnneeCode = [NOMBRE MATIERES].AnneeCode)) INNER JOIN [PRIX UHT MATIERES] ON (MATIERES.MatCode = [PRIX UHT MATIERES].MatCode) AND (ANNEE.AnneeCode = [PRIX UHT MATIERES].AnneeCode) WHERE [MATIERES TYPE].MatTypeDesc=" &
"'" & TypeMatDesc &
""AND ANNEE.AnneeDesc=" &
"AnneeDesc &
"';"

'{Execution de la requette et recuperation du resultat}
JeListMat.DataSource = connex.Execute(ReqListMat)

'{Remise a zero du datagridview}
DgvListMatPrem.Rows.Clear()

'{Initialisation des totaux
LongueurTotMat = 0
PoidsTotArMat = 0
PrixUHTArTotMat = 0

While
Not JeListMat.EOF

'{Initialisation des variables}
Designation = JeListMat.Fields.Item(
"MatDesc").Value
Nbre = JeListMat.Fields.Item(
"MatNombre").Value
Longueur = JeListMat.Fields.Item(
"Longueur").Value

'{cumule de la longueur de chaques matieres}
LongueurTotMat = LongueurTotMat + Longueur

'{Initialisation des variables (suite)}
Poids = JeListMat.Fields.Item(
"MatPoids").Value
PrixUHT = JeListMat.Fields.Item(
"MatPrixUHT").Value

'{Incertion et calculs}
'{calcul du poids total}
PoidsT = CalcPoidsTot(Longueur, Poids)

'{calcul de l'arrondit du poids total}
ArPoidsTot = CalcArPoidsTot(PoidsT)

'{cumule du poids arrondis de chaques matieres}
PoidsTotArMat = PoidsTotArMat + ArPoidsTot

'{calcul du prix total}
PrixTot = CalcPrixTot(PrixUHT, Longueur)

'{calcul de l'arrondit du prix total}
PrixTotAr = CalcPrixTotAr(PrixTot)
PrixUHTArTotMat = PrixUHTArTotMat + PrixTotAr

'{Affichage du Datagridview}DgvListMatPrem.Rows.Add(Designation, Nbre, Longueur, Poids, PoidsT, ArPoidsTot, PrixUHT, PrixTot, PrixTotAr)
JeListMat.MoveNext()

Merci de vôtre aide

1 réponse

xtremboxman Messages postés 4 Date d'inscription mercredi 9 janvier 2008 Statut Membre Dernière intervention 16 janvier 2008
16 janv. 2008 à 08:06
C'est bon j'ai reussi
Bonne journée à tous
0
Rejoignez-nous