【问题标题】:Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed检索具有 CLSID {00024500-0000-0000-C000-000000000046} 的组件的 COM 类工厂失败
【发布时间】:2017-05-09 19:20:20
【问题描述】:

我正在尝试读取从第 3 方站点下载的 .xls 文件。我不会每天处理文件,所以我不能在上传文件之前将格式更改为.xlsx

我不断收到以下错误: Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80070005 Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)).

我正在使用带有IIS7vb.net 网站。 应用程序池使用我的用户登录,我的用户是服务器上的管理员,可以访问所有内容。

我做了以下事情:

  • Office 安装在主机上
  • 我已进入DCOMCNFG 并确保Launch and Activation PermissionsAccess PermissionsConfiguration Permissions 可以完全控制我的登录帐户。
  • 服务器有x64架构,我也安装了Office x64
  • 我已确认文件夹C:\Windows\SysWOW64\config\systemprofile\Desktop 以及C:\Windows\SysWOW64\config\systemprofile\Desktop 确实存在。
  • 我知道C:\Windows\SysWOW64\config\systemprofile\Desktop 用于 x86 架构,但我确保它存在以防系统想要使用它。

这是我的代码的样子:

Imports genlib

Imports Excel = Microsoft.Office.Interop.Excel

Partial Class HeadOffice_OpperationalParameters_FailedBranches
    Inherits System.Web.UI.Page

    Private Sub releaseObject(ByVal obj As Object)
        Try
            System.Runtime.InteropServices.Marshal.ReleaseComObject(obj)
            obj = Nothing
        Catch ex As Exception
            obj = Nothing
        Finally
            GC.Collect()
        End Try
    End Sub

    Protected Sub btnRunReport_Click(sender As Object, e As EventArgs) Handles btnRunReport.Click
        If fuReport.HasFile = False Then
            ClientScript.RegisterClientScriptBlock(Me.GetType, "", "alert('Upload a file to process.');", True)
            Exit Sub
        End If

        Dim ReportFileName As String = Server.MapPath("~") & "FilesUploaded\" & fuReport.FileName.Replace(".XLS", "_" & Today.ToString("yyyy.MM.dd") & "_" & TimeOfDay.ToString("HH.mm.ss") & ".xls")
        fuReport.SaveAs(ReportFileName)

        Dim xlApp As Excel.Application 'Here
        Dim xlWorkbook As Excel.Workbook
        Dim xlWorksheet As Excel.Worksheet

        Try
        '=================================================
        ' ERROR OCCURS ON NEXT LINE
        '=================================================
            xlApp = New Excel.ApplicationClass
            xlWorkbook = xlApp.Workbooks.Open(ReportFileName)
            xlWorksheet = xlWorkbook.Worksheets("RptTransactionDetail")

            BrowserWrite(xlWorksheet.Cells(2, 2).value, True)
            xlWorkbook.Close()
            xlApp.Quit()
        Catch ex As Exception
            ClientScript.RegisterClientScriptBlock(Me.GetType, "", "alert('" & ex.Message.Replace("'", "\'").Replace(vbCr, "\r").Replace(vbLf, "\n") & "');", True)
            Exit Sub
        End Try

        releaseObject(xlApp)
        releaseObject(xlWorkbook)
        releaseObject(xlWorksheet)

    End Sub
End Class

谁能告诉我如何解决这个错误,或者采取什么步骤来确定问题?

我已经阅读了大多数关于堆栈溢出的帖子,但是有太多帖子无法添加我看过的每个答案。

【问题讨论】:

  • 错误出现在哪一行?
  • @dbasnett 在第 33 行:xlApp = New Excel.ApplicationClass
  • 你试过xlApp = New Excel.Application
  • @dbasnett 我刚试过那个代码,它仍然给我同样的错误:Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80070005 Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)).
  • Microsoft 不建议在 Web 服务器上使用 Interop。我怀疑您遇到了这些问题之一。见support.microsoft.com/en-us/help/257757/…

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


【解决方案1】:

我正在使用带有 IIS7 的 vb.net 站点

Microsoft 目前不推荐也不支持任何无人值守、非交互式客户端应用程序或组件(包括 ASP、ASP.NET、DCOM 和 NT 服务)的 Microsoft Office 应用程序自动化,因为 Office 可能表现出不稳定Office 在此环境中运行时出现的行为和/或死锁。

如果您要构建在服务器端上下文中运行的解决方案,您应该尝试使用已确保无人值守执行安全的组件。或者,您应该尝试找到允许至少部分代码在客户端运行的替代方案。如果您使用服务器端解决方案中的 Office 应用程序,该应用程序将缺少许多成功运行所需的功能。此外,您将承担整体解决方案稳定性的风险。在Considerations for server-side Automation of Office 文章中阅读更多相关信息。

如果您只处理开放的 XML 文档,作为一种可能的解决方法,您可以考虑使用 Open XML SDK,请参阅Welcome to the Open XML SDK 2.5 for Office。或者只是为服务器端执行而设计的任何第三方组件(例如,Aspose)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-05-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-18
    相关资源
    最近更新 更多