簡體   English   中英

Microsoft Office Excel 無法訪問 IIS 上的文件

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

我有一個網絡服務方法,它在給定的 Excel 文件中搜索字符串並返回其狀態。 這在 VS 項目中工作正常。 但是當我在 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);

我已經檢查過filePath C:\\inetpub\\wwwroot\\MyFirstWebService\\App_Data\\Results.xlsx並且沒問題。

我也嘗試過像下面這樣的幾個在線解決方案,但它還沒有修復:

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")

為什么它在 VS 上而不是在 IIS 上工作? 我的用戶帳戶也獲得了管理員權限,想知道為什么它不起作用。

謝謝

我在從 IIS 上托管的 MVC 應用程序讀取 Excel 時遇到問題。 從 IIS 訪問 Excel 有兩件事很重要。

  1. 必須有“C:\\Windows\\SysWOW64\\config\\systemprofile\\Desktop”。 即 SysWOW64 文件夾中的 Desktop 文件夾,32 位的 System32 文件夾。
  2. 將完全訪問權限分配給桌面文件夾上的 IIS_IUSRS 用戶。

這有點奇怪,不知道為什么需要這樣做,但對我有用。

我遇到了這個問題,在任何地方都找不到解決方案。 這里有多個問題。 IIS應用程序位於64位Windows Server 2008上,但Office的安裝版本為32位版本。

本文為我指出了正確的方向:

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

但是,為了安全起見,我不得不將Dcom Config中Microsoft Excel應用程序的身份更改為管理員而不是啟動用戶。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM