Bonjour
voila le code que je regler pour exporter les donnes d'un datagrid vers un fichier excel qui se trouve dans le bin de mon application mais le probleme c'est que ce code affiche seulement le dernier enregistrement. Pouvez vous m'aider a developper ce code pour afficher les donnees dans les cellules précisées
Et merci d'avance
Voila le code: v1 est un view
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
Dim app As New Microsoft.Office.Interop.Excel.Application
app.Workbooks.Open(System.Environment.CurrentDirectory & "\etat2.xls")
app.Visible = True
'dss.Clear()
Call connect()
Cmd.CommandText = "select N_ARRIVE,NOM_EXPD,DATE_ARRIVE,LIBELLE_DEPART from v1 where (DATE_ARRIVE between '" & Me.DateTimePicker1.Value & "' and '" & Me.DateTimePicker2.Value & "') and LIBELLE_DEPART like '" & Me.ComboBox1.Text & "'"
'Cmd.CommandText = "select N_ARRIVE,NOM_EXPD,DATE_ARRIVE,LIBELLE_DEPART from v1 "
Cmd.Connection = Cnx
Cmd.CommandType = CommandType.Text
dr = Cmd.ExecuteReader
Dim i As Integer = 0
 
dr.Read()
app.Cells(2, 3) = dr(3)
 
While dr.Read
 
app.Cells(6 + i, 1) = dr(0)
app.Cells(6 + i, 2) = dr(1)
app.Cells(6 + i, 3) = dr(2)
i = +1
 
End While
 
'app.Visible = True
'app.Workbooks.Add()
dr.Close()
Cnx.Close()
 
 
app.Worksheets.PrintPreview()