简体   繁体   English

IIS内的Excel workbook.saveas

[英]Excel workbook.saveas inside IIS

I have a problem when I published web application in IIS 在IIS中发布Web应用程序时出现问题

sometimes the WorkBook.SaveAs method works fine, sometimes not. 有时WorkBook.SaveAs方法可以正常工作,有时则不能。

Description: An unhandled exception occurred during the execution of the current web request. 说明:执行当前Web请求期间发生未处理的异常。 Please review the stack trace for more information about the error and where it originated in the code. 请查看堆栈跟踪,以获取有关错误及其在代码中起源的更多信息。

Exception Details: System.Runtime.InteropServices.COMException: The remote procedure call failed. 异常详细信息:System.Runtime.InteropServices.COMException:远程过程调用失败。 (Exception from HRESULT: 0x800706BE) (来自HRESULT的异常:0x800706BE)

Source Error: 源错误:

    workbook.Saved = True
    workbook.SaveAs(Server.MapPath("~/MyFolder/Excel.xlsx"))
    workbook.Close()
    APP.Quit()

and sometimes the error is on APP.Quit 有时错误是在APP.Quit上

Well the first thing to note, is that office interop is not supported server side by Microsoft, due to both licensing and stability/reliability issues: 首先要注意的是,由于许可和稳定性/可靠性问题,Microsoft 不支持 Office interop 服务器端

Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment. Microsoft当前不建议也不支持任何无人参与的非交互客户端应用程序或组件(包括ASP,ASP.NET,DCOM和NT Services)中的Microsoft Office应用程序自动化,因为Office可能表现出不稳定的行为和/在此环境中运行Office时出现死锁或死锁。

Still, many people do this/try to do this, and run into similar problems as you did. 尽管如此,仍有许多人这样做/尝试这样做,并遇到了与您类似的问题。 Generally this appears to be caused by permission issues (security context and the DCOM security configuration). 通常,这似乎是由权限问题(安全上下文和DCOM安全配置)引起的。 For which different potential solutions have been described, such as 已针对其描述了不同的潜在解决方案,例如

  • How to make IIS7 play nice with Office Interop With a 2 different solutions, one of which is mentioned several times elsewhere: 如何使IIS7与Office Interop配合使用具有两种不同的解决方案,其中一种在其他地方多次提到:

    1. Open Windows Explorer 打开Windows资源管理器
    2. Depending on whether you installed a 32bit or 64bit version of office you will need to do one (or both) of the following: 根据您安装的是32位还是64位版本的Office,您需要执行以下一项(或两项):
      • 32bit Office installation: Navigate to C:\\Windows\\System32\\config\\systemprofile 32位Office安装:导航到C:\\ Windows \\ System32 \\ config \\ systemprofile
      • 64bit Office installation: 64位Office安装:
    3. Navigate to C:\\Windows\\SysWOW64\\config\\systemprofile 导航到C:\\ Windows \\ SysWOW64 \\ config \\ systemprofile
    4. Verify the folder "Desktop" exists (create it if it's not there) 验证文件夹“桌面”是否存在(如果不存在,请创建它)
    5. Right click > Properties 右键单击>属性
    6. On the security tab: Add the account under which the site is running (eg: Network Service) with default permissions (Read & execute; List folder contents; Read) 在安全选项卡上:添加具有默认权限(读取和执行;列出文件夹内容;读取)的运行网站的帐户(例如:网络服务)
  • RPC failure opening an excel document. RPC失败,打开了一个Excel文档。 Listing the following solution: Type Dcomcnfg.exe in Run which opens the dcomconfig utility. 列出以下解决方案:在“运行”中键入Dcomcnfg.exe,这将打开dcomconfig实用程序。

    In the dcomconfig utility, 在dcomconfig实用程序中,

    go to Component Services --> Computers --> My Computer --> DCom Config --> Microsoft Excel Application (and Powerpoint) 转到组件服务->计算机->我的电脑-> DCom配置-> Microsoft Excel应用程序(和Powerpoint)

    Right click it and go to properties. 右键单击它,然后转到属性。 Go to security tab. 转到安全选项卡。 Under Security 在安全之下

    1) Launch & Activation Permissions --> Choose customise and click Edit. 1)启动和激活权限->选择自定义,然后单击编辑。 Add User Network Service and check everything under Allow for it. 添加用户网络服务,并检查“允许”下的所有内容。

    2) Do the same for Access Permissions and Configuration Permissions. 2)对“访问权限”和“配置权限”执行相同的操作。

    Then click Apply and close everything. 然后单击“应用”并关闭所有内容。

  • Another one using Windows Server 2003 , with a different solution 另一种使用Windows Server 2003的解决方案

    It turns out that there was some kind of permission that the COM Object needed. 事实证明,COM对象需要某种许可。 Setting the AppPool (for the site) on the Win2003 server to "SYSTEM" fixed the problem. 将Win2003服务器上的AppPool(用于站点)设置为“ SYSTEM”可以解决此问题。 For some reasion (by Default) the ASPNET account has permission to whatever the COM object was trying to access. 对于某些用途(默认情况下),ASPNET帐户有权访问任何COM对象尝试访问的内容。

Perhaps one of these solutions will work for you. 这些解决方案之一可能会为您服务。

The reason it sometimes works for you and not other times, may be related to the contents of the specific excel file, eg whether it contains any VBA scripts or references any (specific) modules. 它有时对您有用而不是在其他时间不起作用的原因可能与特定excel文件的内容有关,例如,它是否包含任何VBA脚本或引用任何(特定)模块。 So that is something you should look into. 所以这是您应该研究的。

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

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