在vb.net 3.5中创建Excel实例时的System.Runtime.InteropServices.COMException(0x80010108)

时间:2012-10-22 16:36:20

标签: .net vb.net office-interop excel-interop

所以,我有一个启动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

项目主管使用与我(2010年)完全相同的Excel版本,任何人都可以想到为什么会出现这种情况,以及我如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

试试这个

xlsApp = CreateObject("Excel.Application")
xlsBook = xlsApp.Workbooks.Add
xlsSheet = xlsBook.Worksheets.Add