Bonjour à tous,

Je souhaite exporter plusieurs gridview dans un excel mais j'ai quelques problèmes. Voici mon code :

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
Public Sub exportExcel(ByVal listCheckBox As CheckBoxCustom)
 
     Dim xlApp As Excel.Application
     Dim xlWorkBook As Excel.Workbook
     Dim xlWorkSheet As Excel.Worksheet
     Dim misValue As Object = System.Reflection.Missing.Value
 
     Dim gv As GridView = _fullBatch.fullBatch(listCheckBox.batchID, listCheckBox.jobValues, listCheckBox.subJobValues, listCheckBox.layer)
 
     xlApp = New Excel.ApplicationClass
     xlWorkBook = xlApp.Workbooks.Add(misValue)
     xlWorkSheet = xlWorkBook.Sheets("Feuil1")
 
     For Each col In gv.Columns
          For Each row In gv.Rows
               xlWorkSheet.Cells(colCpt + 1, rowCpt + 1) = row
               rowCpt += 1
          Next
          colCpt += 1
     Next
 
 
     xlWorkSheet.SaveAs("C:\....xlsx")
     xlWorkBook.Close()
     xlApp.Quit()
     releaseObject(xlApp)
     releaseObject(xlWorkBook)
     releaseObject(xlWorkSheet)
 
End Sub
Ma méthode fullBatch :

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
Public Function fullBatch(ByVal batchID As String, ByVal jobName As String, ByVal subJobName As String, ByVal layerID As String) As GridView
 
     Dim gridView As New GridView
 
     Dim selectBatch As SqlCommand = New SqlCommand(...)
 
     With selectBatch.Parameters
     ....
     End With
 
     With selectBatch
     ....
     .Connection = _connection.getConnection()
     .CommandType = CommandType.StoredProcedure
     End With
 
     Try
          If _connection.getConnection.State = ConnectionState.Closed Then _connection.openConnection()
 
               gridView.AutoGenerateColumns = False
 
               Dim dscmd As New SqlDataAdapter(selectBatch)
 
               Dim ds As New DataSet
               dscmd.Fill(ds)
               gridView.DataSource = ds.Tables(0)
 
               gridView.DataBind()
 
               Return gridView
 
          Catch ex As Exception
               Console.Write(ex.Message)
               Return Nothing
          Finally
               _connection.closeConnection()
     End Try
End Function
Le truc c'est que gv.Columns est toujours égal à 0 alors que le gv.Row contient des données.

Quelqu'un a une idée ou une autre méthode ?

Merci