Cannot open Excel file in C#

后端 未结 4 1765
天涯浪人
天涯浪人 2021-02-19 21:51

I have the following C# function in my project, which is supposed to open and return an existing Excel workbook object:

Application _excelApp;

// ...

private W         


        
4条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-19 22:01

    I found the following page:

    http://social.msdn.microsoft.com/Forums/en-US/b81a3c4e-62db-488b-af06-44421818ef91/excel-2007-automation-on-top-of-a-windows-server-2008-x64

    Where it says that...

    it’s not supported to automate office products UI less. It seems that Windows Server 2008 and Excel 2007 enforce the given statement.

    The questioner then describes exactly the situation I am in with a Windows Service that cannot open an Excel file, although the same code in a command-line program has no problem.

    The response advises to create the following folder:

    Windows 2008 Server x64: C:\Windows\SysWOW64\config\systemprofile\Desktop

    Windows 2008 Server x86: C:\Windows\System32\config\systemprofile\Desktop

    I have tried this and it worked a treat! Can anyone explain why it is needed and any downsides?

    Thanks,

    --- Alistair.

提交回复
热议问题