简体   繁体   English

Microsoft Office Excel 无法访问 IIS 上的文件

[英]Microsoft Office Excel cannot access the file on IIS

I have a web service method which search string in given Excel file and return its status.我有一个网络服务方法,它在给定的 Excel 文件中搜索字符串并返回其状态。 This is working okay in VS project.这在 VS 项目中工作正常。 But when I public same web service in IIS its throwing error: I'm working on Windows7 machine但是当我在 IIS 中公开相同的 Web 服务时,它抛出错误:我在 Windows7 机器上工作

System.Runtime.InteropServices.COMException: Microsoft Office Excel cannot access the file 'C:\inetpub\wwwroot\MyFirstWebService\App_Data\Results.xlsx'. There are several possible reasons:

• The file name or path does not exist.
• The file is being used by another program.
• The workbook you are trying to save has the same name as a currently open workbook.


string filePath = Server.MapPath("~") + @"\App_Data\Results.xlsx";
            xlApp = new Excel.Application();
            xlWorkBook = xlApp.Workbooks.Open(filePath, 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
            xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);

I have checked filePath C:\\inetpub\\wwwroot\\MyFirstWebService\\App_Data\\Results.xlsx and it is okay.我已经检查过filePath C:\\inetpub\\wwwroot\\MyFirstWebService\\App_Data\\Results.xlsx并且没问题。

I also tried with few online solutions like below, But its not fixed yet:我也尝试过像下面这样的几个在线解决方案,但它还没有修复:

Create directory "C:\Windows\SysWOW64\config\systemprofile\Desktop " (for 64 bit Windows) or 
"C:\Windows\System32\config\systemprofile\Desktop " (for 32 bit Windows)

Set Full control permissions for directory Desktop (for example in Win7 & IIS 7 & DefaultAppPool set permissions for user 
    "IIS AppPool\DefaultAppPool")

Why it's working on VS not on IIS?为什么它在 VS 上而不是在 IIS 上工作? my user account got admin right too, wonder why its not working.我的用户帐户也获得了管理员权限,想知道为什么它不起作用。

Thanks谢谢

I was having issue while reading the Excel from MVC application hosted on IIS.我在从 IIS 上托管的 MVC 应用程序读取 Excel 时遇到问题。 Two things are important for accessing the Excel from IIS.从 IIS 访问 Excel 有两件事很重要。

  1. Must have "C:\\Windows\\SysWOW64\\config\\systemprofile\\Desktop".必须有“C:\\Windows\\SysWOW64\\config\\systemprofile\\Desktop”。 ie Desktop folder in SysWOW64 folder, System32 folder for 32 bit.即 SysWOW64 文件夹中的 Desktop 文件夹,32 位的 System32 文件夹。
  2. Assign full access to IIS_IUSRS user on Desktop folder.将完全访问权限分配给桌面文件夹上的 IIS_IUSRS 用户。

It`s kind of weired, not sure why this is required but worked for me.这有点奇怪,不知道为什么需要这样做,但对我有用。

I ran into this problem and couldn't find a solution anywhere. 我遇到了这个问题,在任何地方都找不到解决方案。 There were multiple issues at play here. 这里有多个问题。 The IIS application was on a 64 bit Windows server 2008 but the installed version of office was a 32 bit version. IIS应用程序位于64位Windows Server 2008上,但Office的安装版本为32位版本。

This article pointed me in the right direction: 本文为我指出了正确的方向:

http://blogs.technet.com/b/the_microsoft_excel_support_team_blog/archive/2012/11/12/microsoft-excel-does-not-appear-in-dcom-configuration-snap-in.aspx http://blogs.technet.com/b/the_microsoft_excel_support_team_blog/archive/2012/11/12/microsoft-excel-does-not-appear-in-dcom-configuration-snap-in.aspx

However, instead of security i had to change the identity of the Microsoft Excel Application in Dcom Config to be an administrator instead of the launching user. 但是,为了安全起见,我不得不将Dcom Config中Microsoft Excel应用程序的身份更改为管理员而不是启动用户。

暂无
暂无

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

相关问题 Microsoft Excel 无法访问文件“...”。 使用 Microsoft Office 2010 的 Windows Server 2008 R2 有多种可能的原因 - Microsoft Excel cannot access the file “…”. There are several possible reasons Windows Server 2008 R2 with Microsoft Office 2010 Microsoft Office Excel 无法访问文件'c:\inetpub\wwwroot\Timesheet\App_Data\Template.xlsx' - Microsoft Office Excel cannot access the file 'c:\inetpub\wwwroot\Timesheet\App_Data\Template.xlsx' “无法加载文件或程序集”- Microsoft.Office.Interop.Excel - "Cannot load file or assembly" - Microsoft.Office.Interop.Excel Microsoft Office Access 数据库引擎无法打开或写入文件 - The Microsoft Office Access database engine cannot open or write to the file Microsoft Office Access 数据库引擎无法打开或写入文件 '' - The Microsoft Office Access database engine cannot open or write to the file '' 尝试查询Excel文件时出现问题…“ Microsoft Office Access数据库引擎找不到对象'Sheet1 $'。” - Issue attempting to query an Excel file… “The Microsoft Office Access database engine could not find the object 'Sheet1$'..” Microsoft Excel无法访问Windows Server 2012上的文件 - Microsoft Excel cannot access the file on Windows Server 2012 Microsoft Excel无法访问文件'C:\\ 0BBAC500' - Microsoft Excel cannot access the file 'C:\0BBAC500' Microsoft Excel无法访问ASP.net Project中的文件 - Microsoft Excel cannot access the file in ASP.net Project Microsoft Office Interop Excel-指定Excel文件的名称 - Microsoft Office Interop Excel - Specify name of Excel file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM