HOME > .NET Framework > Forum > เรื่องการ อ่านไฟร์ Excel System.Runtime.InteropServices.COMException: Old format or invalid type library. (Exception from HRESULT: 0x80028018 (TYPE_E_
เรื่องการ อ่านไฟร์ Excel System.Runtime.InteropServices.COMException: Old format or invalid type library. (Exception from HRESULT: 0x80028018 (TYPE_E_
พี่ครับผมทำตามDemo ที่ให้มาแล้วเกิด ex
System.Runtime.InteropServices.COMException: Old format or invalid type library. (Exception from HRESULT: 0x80028018 (TYPE_E_INVDATAREAD))
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim objBooks As Excel.Workbooks
Dim objSheets As Excel.Sheets
Dim objSheet As Excel._Worksheet
Dim range As Excel.Range
' Create a new instance of Excel and start a new workbook.
objApp = New Excel.Application()
System.Threading.Thread.CurrentThread.CurrentCulture = New System.Globalization.CultureInfo("en-US")
objBooks = objApp.Workbooks
objBook = objBooks.Add
objSheets = objBook.Worksheets
objSheet = objSheets(1)
'Get the range where the starting cell has the address
'm_sStartingCell and its dimensions are m_iNumRows x m_iNumCols.
range = objSheet.Range("A1", Reflection.Missing.Value)
range = range.Resize(5, 5)
If (Me.FillWithStrings.Checked = False) Then
'Create an array.
Dim saRet(5, 5) As Double
'Fill the array.
Dim iRow As Long
Dim iCol As Long
For iRow = 0 To 5
For iCol = 0 To 5
'Put a counter in the cell.
saRet(iRow, iCol) = iRow * iCol
Next iCol
Next iRow
'Set the range value to the array.
range.Value = saRet
Else
'Create an array.
Dim saRet(5, 5) As String
'Fill the array.
Dim iRow As Long
Dim iCol As Long
For iRow = 0 To 5
For iCol = 0 To 5
'Put the row and column address in the cell.
saRet(iRow, iCol) = iRow.ToString() + "|" + iCol.ToString()
Next iCol
Next iRow
'Set the range value to the array.
range.Value = saRet
End If
'Return control of Excel to the user.
objApp.Visible = True
objApp.UserControl = True
'Clean up a little.
range = Nothing
objSheet = Nothing
objSheets = Nothing
objBooks = Nothing
End Sub