I want to import my Excel .xlsx file into a datatable in vb.net in order to process the data later. My Excel file called Data.xlsx looks like this:
Référence | Date | Concerned Numbers | Comment |
---|---|---|---|
2022-A34 | 24.01.2022 | 738/3784 | Checked |
2022-A36 | 28.01.2022 | 7/3, 8733/28373,938/24755 |
and tried to use the code given by Ciarán here: Best /Fastest way to read an Excel Sheet into a DataTable?
Dim sSheetName As String = ""
Dim sConnection As String
Dim nOutputRow As Integer = 0
Dim dtTablesList As DataTable
Dim oleExcelCommand As OleDb.OleDbCommand
Dim oleExcelReader As OleDb.OleDbDataReader
Dim oleExcelConnection As OleDb.OleDbConnection
sConnection = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=E:\Folder\Data.xlsx;Extended Properties=""Excel 12.0;HDR=No;IMEX=1"""
oleExcelConnection = New OleDb.OleDbConnection(sConnection)
oleExcelConnection.Open()
dtTablesList = oleExcelConnection.GetSchema("Tables")
If dtTablesList.Rows.Count > 0 Then
sSheetName = dtTablesList.Rows(0)("TABLE_NAME").ToString
End If
dtTablesList.Clear()
dtTablesList.Dispose()
If sSheetName <> "" Then
oleExcelCommand = oleExcelConnection.CreateCommand()
oleExcelCommand.CommandText = "Select * From [" & sSheetName & "]"
oleExcelCommand.CommandType = CommandType.Text
oleExcelReader = oleExcelCommand.ExecuteReader
nOutputRow = 0
While oleExcelReader.Read
End While
oleExcelReader.Close()
End If
oleExcelConnection.Close()
My problem is now that when I run that code and check the dtTablesList
to see the content, the whole table is basically empty.
I only see this:
Am I missing here something or is my approach totally wrong?