![](/img/trans.png)
[英]Microsoft Excel cannot access the file “…”. There are several possible reasons Windows Server 2008 R2 with Microsoft Office 2010
[英]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 有兩件事很重要。
這有點奇怪,不知道為什么需要這樣做,但對我有用。
我遇到了這個問題,在任何地方都找不到解決方案。 這里有多個問題。 IIS應用程序位於64位Windows Server 2008上,但Office的安裝版本為32位版本。
本文為我指出了正確的方向:
但是,為了安全起見,我不得不將Dcom Config中Microsoft Excel應用程序的身份更改為管理員而不是啟動用戶。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.