【发布时间】: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)).
我正在使用带有IIS7 的vb.net 网站。
应用程序池使用我的用户登录,我的用户是服务器上的管理员,可以访问所有内容。
我做了以下事情:
- Office 安装在主机上
- 我已进入
DCOMCNFG并确保Launch and Activation Permissions、Access Permissions和Configuration 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