调用 Microsoft.Office.Interop.Excel 的 COM 组件返回错误 HRESULT E_FAIL

Error HRESULT E_FAIL has been returned from a call to a COM component for Microsoft.Office.Interop.Excel

我正在尝试使用 asp.net 页面中的 Excel 文件对话框 window。它在我的本地计算机上运行良好,但在服务器上出现以下错误。

System.Runtime.InteropServices.COMException: Error HRESULT E_FAIL has been returned from a call to a COM component.

[COMException (0x80004005): Error HRESULT E_FAIL has been returned from a call to a COM component.] Microsoft.Office.Interop.Excel.ApplicationClass.get_FileDialog(MsoFileDialogType fileDialogType) +0 FileMoverSetup.FileDirectorySetup.btnProcessedBrowse_Click(Object sender, EventArgs e) in c:\Users\psanders\Documents\Visual Studio 2013\Projects\FileMoverSetup\FileMoverSetup\FileDirectorySetup.aspx.cs:390 System.Web.UI.WebControls.Button.OnClick(EventArgs e) +9628722 System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +103 System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1724

我已经为此工作好几天了,但没有任何运气。有什么建议吗??

编辑

这就是我要说的。它在我的盒子上工作得很好,但是当我把它放在服务器上时,它出现了上述错误。

我在另一个论坛上收到了这个回复。

... and it never will.

First, it only ever works on your DEV machine because everything, including the web server, is running as YOU on your desktop.

When deployed on the server, everything runs as a service without any visible desktop. So, the dialog that shows up only shows up on the web server where nobody can see it. The dialog will NEVER show up on the client machine.

Also, Excel Interop (what you're doing) can NOT be used in a web application for various reasons, like re-entrancy and multiple thread problems. It may work so long as one user at a time is using a function in the website but it will fall on its face and crash with the more users using the functions at the same time.

from Dave Kreskowiak on code project

所以我打算尝试找到一种新方法 using/creating 文件夹选择对话框。