有时,在运行下面的代码时,调用IErrorInfo.GetDescription failed with E_FAIL(0x80004005)
会导致错误excelFile.WorksheetNoHeader(0)
。
它似乎不依赖于excel文件,一个文件可以读取一次,下一次不可读。
任何想法可能是什么原因?
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