2015-04-20 2 views
0

У меня проблема, когда я опубликовал веб-приложение в IISExcel workbook.saveas внутри IIS

Иногда метод WorkBook.SaveAs работает нормально, иногда нет.

Description: An unhandled exception occurred during the execution of the current web request. 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. (Exception from HRESULT: 0x800706BE)

Источник ошибки:

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

и иногда ошибка на APP.Quit

ответ

0

Ну первое, что нужно отметить, это то, что офис Interop является not supported server side от Microsoft, из-за как вопросы лицензирования, так и устойчивость/надежность:

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.

Тем не менее, многие люди делают это/пытаются сделать это и сталкиваются с аналогичными проблемами, как вы. Как правило, это вызвано проблемами разрешения (контекст безопасности и конфигурация безопасности DCOM). Для которых различные возможные решения были описаны, например,

  • How to make IIS7 play nice with Office Interop С помощью 2-х различных решений, одним из которых несколько раз упоминается в других местах:

    1. Open Windows Explorer
    2. Depending on whether you installed a 32bit or 64bit version of office you will need to do one (or both) of the following:
      • 32bit Office installation: Navigate to C:\Windows\System32\config\systemprofile
      • 64bit Office installation:
    3. Navigate to 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. Листинг следующее решение: Тип Dcomcnfg.exe в Run, который открывает утилиту dcomconfig.

    In the dcomconfig utility,

    go to Component Services --> Computers --> My Computer --> DCom Config --> Microsoft Excel Application (and Powerpoint)

    Right click it and go to properties. Go to security tab. Under Security

    1) Launch & Activation Permissions --> Choose customise and click Edit. Add User Network Service and check everything under Allow for it.

    2) Do the same for Access Permissions and Configuration Permissions.

    Then click Apply and close everything.

  • Another one using Windows Server 2003, с другим раствором

    It turns out that there was some kind of permission that the COM Object needed. Setting the AppPool (for the site) on the Win2003 server to "SYSTEM" fixed the problem. For some reasion (by Default) the ASPNET account has permission to whatever the COM object was trying to access.

Возможно, один из этих решений будет работать для вас.

Причина, по которой она иногда работает для вас, а не в другое время, может быть связана с содержимым конкретного файла excel, например. содержит ли он какие-либо скрипты VBA или ссылки на какие-либо (определенные) модули. Так что вы должны изучить.

+0

Я сделал эти два решения, вот почему я задал вопрос –

+0

Ну, вы не сказали, что вы что-то пробовали, так как я должен был это знать. Вы должны включить то, что вы пробовали, и не решили свои проблемы в своем вопросе. – Alex

+0

Извините за это, Я думаю, что иногда это работает, потому что я делал эти решения, но почему бы и нет ошибки. –

Смежные вопросы