简体   繁体   English

无法访问IIS服务器上的Excel文件

[英]Not able to access Excel File on IIS Server

I have developed an asp.net application. 我已经开发了一个asp.net应用程序。 In that application I created the Interop Object with the help of which I am opening an Excel file.This thing works fine at the Local system. 在该应用程序中,我创建了一个Interop对象,并借助该对象打开了一个Excel文件。 But when I try to open the application from the Localhost IIS Server it is showing me the error that Microsoft Excel cannot access the file.I have used the following code. 但是,当我尝试从Localhost IIS服务器打开应用程序时,它向我显示Microsoft Excel无法访问该文件的错误。我使用了以下代码。

            addBatch.WA = new Excel.Application();

            addBatch.workbookPath = @"D:\Barcode_Details.xlsx";
            addBatch.excelWorkbook = WA.Workbooks.Open(workbookPath, 0, false, 5, "", "", false, Excel.XlPlatform.xlWindows, "", true, false, 0, true, false, false);

            addBatch.excelSheets = excelWorkbook.Worksheets;

Basically, You don't have rights to access files on your computer, except them in your virtual dir! 基本上,除了虚拟目录中的文件,您无权访问计算机上的文件! So, you need to put the excell file in your project directory, for example in App_Data and then change the path as follows 因此,您需要将excell文件放在您的项目目录中,例如在App_Data中,然后按如下所示更改路径

   addBatch.workbookPath = Server.MapPath("~/App_Data/Barcode_Details.xlsx");

Add your code in try catch block, and try extract the error message 将代码添加到try catch块中,然后尝试提取错误消息

if the error is Dynamic operations cannot be performed on the homogenous AppDomain then go to the Web.config file of port no 80 try to change trust legacyCasModel=false level="Full" 如果错误是“动态操作无法在同一个AppDomain上执行”,则转到端口80的Web.config文件,尝试更改信任的legacyCasModel = false level =“ Full”

if the error is Access Denied of Com Exception win+r->dcomcnfg->componentservices-> computer->dcom config ->microsoft Excel Application-> rightclick to get properties 如果错误是访问权限被拒绝,请执行以下操作:win + r-> dcomcnfg-> componentservices->计算机-> dcom配置-> Microsoft Excel应用程序->右键单击以获取属性

In general tab change authentication type to None. 在常规选项卡中,将身份验证类型更改为无。

I hope it solves! 我希望它能解决! i faced the same issue 我遇到了同样的问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM