Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim frm As New OpenFileDialog With frm .ShowDialog()
If .FileName <> "" Then Dim strCon As String = "" If .FileName.EndsWith(".xlsx") Then strCon = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & .FileName & ";Extended Properties=""Excel 12.0 Xml;HDR=Yes"";" Else strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & .FileName & ";Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1"";" End If
Dim strSQL As String = "SELECT * FROM [Sheet1$]"
Using adp As New Data.OleDb.OleDbDataAdapter(strSQL, strCon), dtbRet As New DataTable adp.Fill(dtbRet) TextBox1.Text = dtbRet.Rows(0)(0) End Using End If End With End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim frm As New OpenFileDialog With frm .ShowDialog()
If .FileName <> "" Then Dim strCon As String = "" If .FileName.EndsWith(".xlsx") Then strCon = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & .FileName & ";Extended Properties=""Excel 12.0 Xml;HDR=Yes"";" Else strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & .FileName & ";Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1"";" End If
Dim strSQL As String = "SELECT * FROM [Sheet1$]"
Using adp As New Data.OleDb.OleDbDataAdapter(strSQL, strCon), dtbRet As New DataTable adp.Fill(dtbRet) TextBox1.Text = dtbRet.Rows(0)(0) End Using End If End With End Sub