Upload
kzelda
View
121
Download
5
Embed Size (px)
DESCRIPTION
Importer un fichier excel dans une application VB.NET
Citation preview
D:\khaled\code util\Importer_Fichier_Excel_vb.net.vb lundi 11 octobre 2010 15:01
'Importer un fichier Excel dans une app VB.NET en utilisant OLEDB'Created By k++Public Function ImportExcelDataGrid(ByVal Path_Excel_File As String, ByVal DataGrid1
As DataGrid)Try
Dim conn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source='" &Path_Excel_File & "';Extended Properties=Excel 8.0;User ID=Admin;Password="
Dim connexion As OleDbConnection = New OleDbConnection(conn)
connexion.Open()'On récupère le schéma de la base (tables)Dim dt As DataTable = connexion.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,
Nothing)
If IsNothing(dt) ThenExit Function
End If
'Ouvrir la première page du fichier excelDim cmd As String = "Select * from " & dt.Rows(0)("TABLE_NAME")
Dim adapter As New OleDbDataAdapter(cmd, conn)
Dim topics As New Data.DataSet
adapter.Fill(topics)
With DataGrid1.DataSource = topics.Tables(0)
End WithEnd Function
Catch ex As ExceptionMessageBox.Show(ex.Message)
End Try
-1-