所以,我有一个启动 Excel 实例的程序。它适用于我的机器以及其他 2 台机器,但是当我的项目负责人尝试它时,他收到以下错误:
System.Runtime.InteropServices.COMException (0x80010108): Creating an instance of the COM component with CLSID {00024500-0000-0000-C000-000000000046} from the IClassFactory failed due to the following error: 80010108.
下面的代码是我创建 excel 实例并启动它的地方。
Dim xlsApp As New Excel.Application
Dim xlsWB As Excel.Workbook
Dim xlsWS As Excel.Worksheet
Try
If ugLoadDeviationsDetails.DataSource IsNot Nothing Then
'Creates a temporary excel file with data located in the grid
UltraGridExcelExporter1.Export(ugLoadDeviationsDetails, "C:\ProgramData\Data-Tronics\ShellFiles\LoadDeviations\tempExcel")
xlsWB = xlsApp.Workbooks.Open("C:\ProgramData\Data-Tronics\ShellFiles\LoadDeviations\tempExcel")
xlsWS = DirectCast(xlsWB.Sheets("Sheet1"), Excel.Worksheet)
DirectCast(xlsWS.Cells.EntireRow, Excel.Range).ClearFormats()
DirectCast(DirectCast(xlsWS.Cells("1", "A"), Excel.Range).EntireRow().Cells, Excel.Range).Interior.Color = Color.LightGray.ToArgb
DirectCast(xlsWS, Excel.Worksheet).Copy()
xlsWB.Close(False)
xlsApp.Visible = True
xlsApp.UserControl = True
Else
RaiseEvent ShowError("Cannot write file when grid is empty.")
End If
Catch ex As Exception
For Each wb As Excel.Workbook In xlsApp.Workbooks
wb.Close(False)
Next
xlsApp.Quit()
Finally
xlsApp = Nothing
xlsWB = Nothing
xlsWS = Nothing
End Try
根据堆栈跟踪,它在以下行中断:
Dim xlsApp As New Excel.Application
项目负责人使用与我完全相同的 Excel 版本(2010 年),谁能想到为什么会发生这种情况,以及我该如何解决?