منتدى فيجوال بيسك لكل العرب | منتدى المبرمجين العرب
[سؤال] طلب مساعدة في : جلب بيانات من ملف أكسل - نسخة قابلة للطباعة

+- منتدى فيجوال بيسك لكل العرب | منتدى المبرمجين العرب (http://vb4arb.com/vb)
+-- قسم : قسم لغة الفيجوال بيسك VB.NET (http://vb4arb.com/vb/forumdisplay.php?fid=182)
+--- قسم : قسم اسئلة VB.NET (http://vb4arb.com/vb/forumdisplay.php?fid=183)
+--- الموضوع : [سؤال] طلب مساعدة في : جلب بيانات من ملف أكسل (/showthread.php?tid=36262)



طلب مساعدة في : جلب بيانات من ملف أكسل - resali - 30-08-20

أردت جلب بيانات من ملف أكسل


أستعمل Microsoft Visual Basic 2010 Express وكذا قاعدة بيانات أكسس

فأنشات فورم1  وبه radiobutton و button و datagridview

ووضعت هذا الكود 
كود :
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|*.xlxs"
       If ofd.ShowDialog = Windows.Forms.DialogResult.OK Then
           Dim con As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & ofd.FileName & "; extended properties=excel.4.0;")

           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

 وعند التنفيذ تظهر رسالة 

 



وشكرا لكم






RE: طلب مساعدة في : جلب بيانات من ملف أكسل - عيد مبارك - 30-08-20

جرب هذا التعديل بالاضافة لتعديل كلمة xlxs إلى xlsx

كود :
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


RE: طلب مساعدة في : جلب بيانات من ملف أكسل - resali - 30-08-20

جزيل الشكر لك أخي : عيد مبارك

تمت عملية الجلب بنجاح