IIS不打开XLS

我正在尝试打开并更新IIS服务器上的xls文件并将其作为下载发送给用户。 以下代码正在开发IIS Express环境下正常工作。 但是当我将它部署在IIS服务器上时,服务器似乎挂在Workbooks.open函数上。

// Copy template to the given file System.IO.File.Copy(Server.MapPath("~") + "\\App_Data\\template.xls", file, true); // Get current project id int activeProjectID = Convert.ToInt32(Session["activeProjectID"]); // Open workbook oXL = new Microsoft.Office.Interop.Excel.Application(); oXL.Visible = true; oXL.DisplayAlerts = false; mWorkBook = oXL.Workbooks.Open(file, 0, false, 5, "", "", false, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "", true, false, 0, true, false, false); //Get all the sheets in the workbook mWorkSheets = mWorkBook.Worksheets; 

使用Office Interop库的服务器端自动化不是受支持的scheme,而是在寻求麻烦。 它导致了很多问题,因为:

  1. 需要一个用户身份
  2. 他们与桌面进行交互
  3. 他们没有重入性和可扩展性

“Microsoft目前不推荐并不支持从任何无人参与的非交互式客户端应用程序或组件(包括ASP,ASP.NET,DCOM和NT服务)中自动化Microsoft Office应用程序,因为Office可能performance出不稳定的行为, /或Office在此环境中运行时出现死锁。“

https://support.microsoft.com/en-us/help/257757/considerations-for-server-side-automation-of-office