Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
141 views

Importer Un Fichier Excel Dans Une Application

This VB.NET code imports Excel data into a data grid using OLEDB. It opens an Excel file connection, retrieves the table schema, selects all data from the first sheet table, fills a dataset, and sets the dataset as the data source for a data grid. Any errors are caught and displayed in a message box.

Uploaded by

kzelda
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
141 views

Importer Un Fichier Excel Dans Une Application

This VB.NET code imports Excel data into a data grid using OLEDB. It opens an Excel file connection, retrieves the table schema, selects all data from the first sheet table, fills a dataset, and sets the dataset as the data source for a data grid. Any errors are caught and displayed in a message box.

Uploaded by

kzelda
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

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) Then
Exit Function
End If

'Ouvrir la première page du fichier excel


Dim 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 With
End Function

Catch ex As Exception
MessageBox.Show(ex.Message)
End Try

-1-

You might also like