Sometimes when running the code below it results in the error IErrorInfo.GetDescription failed with E_FAIL(0x80004005)
from the call to excelFile.WorksheetNoHeader(0)
.
It doesn't seem to depend on the excel file, one file can be readable one time and the next time not.
Any ideas what could be the cause?
Public Overrides Function GetImportDataAsDataTable() As DataTable
Dim dataTable = New DataTable
dataTable.BeginLoadData()
Try
Dim excelFile = New ExcelQueryFactory(FileFullPath)
For Each importDataRow In excelFile.WorksheetNoHeader(0)
If dataTable.Columns.Count = 0 Then
For i = 1 To importDataRow.Count
dataTable.Columns.Add(New DataColumn())
Next
End If
Dim dataRow = dataTable.NewRow
dataRow.ItemArray = importDataRow.ToArray
dataTable.Rows.Add(dataRow)
Next
Finally
dataTable.EndLoadData()
End Try
Return dataTable
End Function