30-08-20, 01:53 AM
جرب هذا التعديل بالاضافة لتعديل كلمة xlxs إلى xlsx
تم اقتباس الحل من هذا الرابط
VB 2010 Reading xls file
كود :
Imports System.Data.OleDb
Public Class Form1
Private Sub rbtn_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles rbtn.CheckedChanged
Dim ofd As New OpenFileDialog
ofd.Filter = "all files |*.*|excel files|*.xlsx"
If ofd.ShowDialog = Windows.Forms.DialogResult.OK Then
Dim con As New OleDbConnection
If IO.Path.GetExtension(ofd.FileName).ToLower.Equals(".xlsx") Then
con.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & ofd.FileName & ";Mode='ReadWrite';Extended Properties='Excel 12.0 Macro;HDR=Yes;IMEX=1;'"
Else
con.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & ofd.FileName & ";Extended Properties='Excel 8.0;HDR=Yes;IMEX=1'"
End If
Dim da As New OleDbDataAdapter("select * from [etud$]", con)
Dim dt As New DataTable
da.Fill(dt)
DataGridView1.DataSource = dt
Else
Close()
End If
End Sub
End Classتم اقتباس الحل من هذا الرابط
VB 2010 Reading xls file
