I am importing excel worksheets to a datagridview using the following code:
Private Sub Browsimportbtn_Click(sender As Object, e As EventArgs) Handles Browsimportbtn.Click
Dim textpath As String
Dim textpath1 As String
Dim opf As New OpenFileDialog
If opf.ShowDialog = 1 Then
textpath = opf.FileName
textpath1 = opf.SafeFileName
textpath1 = textpath1.Remove(textpath1.Length -4,4)
Dim cnexcell As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & textpath & "; Extended Properties = ""Excel 12.0 Xml;HDR=YES"";")
Dim cmdE As New OleDbCommand("SELECT * FROM Feuil1", cnexcell)
Try
Dim daoledb As New OleDbDataAdapter
Dim dset As New DataSet
daoledb.SelectCommand = cmdE
daoledb.Fill(dset, "Feuil1")
DGVmodele.DataSource = dset.Tables("Feuil1")
Catch ex As Exception
MsgBox(ex.Message)
End Try
End If
End Sub
The code above is working well with .XLSX
files (office 2007,2010...) but do not with .XLS
and i don't know where is the issue.
Any suggestions?