Exporter une data grid vb.net 2008 vers excel

wawiarawia Messages postés 4 Date d'inscription dimanche 18 avril 2010 Statut Membre Dernière intervention 3 mai 2011 - 12 mai 2010 à 18:24
dev74100 Messages postés 1 Date d'inscription mardi 27 avril 2010 Statut Membre Dernière intervention 22 mars 2011 - 22 mars 2011 à 13:12
jé prépare mon PFE avec vb.net et access j'ai une problème je veux exporter le contenu d'un datagrid vers excel mai je n'arrive pas . svp est ce qu'il ya kelk1 ki peu m'aider . c'est urgenttttttttt
merciiiiiiiiiiii d'avence

2 réponses

zidan005 Messages postés 1 Date d'inscription vendredi 22 octobre 2010 Statut Membre Dernière intervention 4 mars 2011
4 mars 2011 à 00:42
J ai un porbleme pour importer et expotrer des enregistrement vers excel
0
dev74100 Messages postés 1 Date d'inscription mardi 27 avril 2010 Statut Membre Dernière intervention 22 mars 2011
22 mars 2011 à 13:12
Private Sub bt_excel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt_excel.Click
Dim rowsTotal, colsTotal As Short
Dim I, j, iC As Short
System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor
Dim xlApp As New Microsoft.Office.Interop.Excel.Application

Try
Dim excelBook As Microsoft.Office.Interop.Excel.Workbook = xlApp.Workbooks.Add
Dim excelWorksheet As Microsoft.Office.Interop.Excel.Worksheet = CType(excelBook.Worksheets(1), Microsoft.Office.Interop.Excel.Worksheet)
xlApp.Visible = True
rowsTotal = DataGridView1.RowCount - 1
colsTotal = DataGridView1.Columns.Count - 1

With excelWorksheet
.Cells.Select()
.Cells.Delete()
For iC = 0 To colsTotal
.Cells(1, iC + 1).Value = DataGridView1.Columns(iC).HeaderText
Next

For I = 0 To rowsTotal
For j = 0 To colsTotal
.Cells(I + 2, j + 1).value = DataGridView1.Rows(I).Cells(j).Value
Next j
Next I

.Rows("1:1").Font.FontStyle = "Bold"
.Rows("1:1").Font.Size = 10
.Cells.Columns.AutoFit()
.Cells.Select()
.Cells.EntireColumn.AutoFit()
.Cells(1, 1).Select()
.Rows("2:2").Font.FontStyle = "Bol"
.Rows("2:2").Font.Size = 10
.Cells.Columns.AutoFit()
.Cells.Select()
.Cells.EntireColumn.AutoFit()
.Cells(1, 2).Select()

End With
Catch ex As Exception
MsgBox("Export Excel Error " & ex.Message)
Finally
'RELEASE ALLOACTED RESOURCES
System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default
xlApp = Nothing

End Try
End Sub
0
Rejoignez-nous