السلام عليكم ورحمة الله وبركاته
حاولت البحث عن طريقة لقراءة بيانات موجودة في ملف اكسيل وعرضها في داتا غريد في فيجوال بيسك دوت نت 2005 ومن ثم تخزين البيانات في الداتابيز
وجدت هذا الكود
' Let the user chose the file they want
Dim xcFileInfo As IO.FileInfo
Dim xcFileDialog As New OpenFileDialog()
xcFileDialog.Filter = "Excel Spreadsheet Files!|*.xls"
xcFileDialog.Title = "Select estimate in excel spreadsheet file!"
If xcFileDialog.ShowDialog = DialogResult.OK Then
xcFileInfo = New IO.FileInfo(xcFileDialog.FileName)
End If
Dim myExcel As Excel.Application ' Interface to Excel
Dim myWorkBookCollection As Excel.Workbooks ' Workbook-collection (note the 's' at the end)
Dim myWorkBook As Excel.Workbook ' Single Workbook (spreadsheet-collection)
Dim myWorkSheet As Excel.Worksheet ' Single spreadsheet
' Initialize the interface to Excel.exe
myExcel = New Excel.Application
If myExcel Is Nothing Then
MessageBox.Show("Could not load Excel.exe")
Exit Sub
End If
' initialise access to Excel's workbook collection
myWorkBookCollection = myExcel.Workbooks
'open spreadsheet from disk
myWorkBook = myWorkBookCollection.Open(xcFileInfo.FullName, , False)
'get 1st sheet from workbook
myWorkSheet = myWorkBook.Sheets.Item(1)
'alter contents of 1st cell
Dim myCell As Object = myWorkSheet.Range("A1", System.Reflection.Missing.Value)
myCell.Value2 = "VB.NET was here!!!"
'display the spreadsheet
'myExcel.Visible = True
'Read Cell A2
Dim myCell2 As Object = myWorkSheet.Range("A2", System.Reflection.Missing.Value)
Me.Text = myCell.Value2
'save and get out
myWorkBook.Save()
myExcel.Quit()مع وجوب اضافة ريفرنس أكسيل
أضفت الرفرنس وجربت الكود لكن هذا السطر
myWorkBook = myWorkBookCollection.Open(xcFileInfo.FullName, , False)
يظهر لي هذا الخطأ
NullRefrenceException was handled
object refrence not set to an instance of an object
ممكن تخبروني معنى الخطأ ،، وهل توجد طريقة أخرى لقراءة الملف
شكرا