【问题标题】:Save excel from .Net windows service/Powershell从 .Net Windows 服务/Powershell 保存 excel
【发布时间】:2025-12-28 17:00:11
【问题描述】:

过去几天我的处境很棘手。我们有一个现有的 Win 2003 服务器并正在迁移到 Win 2008。我已经设置了新的 Win 2008 服务器并面临一个问题。

当前服务器有

Windown service --calls-> .Net exe --calls-> powershell script --calls-> excel introp的workbook.SaveAs()

一切正常。 .net版本是4.0,powershell版本是2.0,MS Office版本是2007。

在新服务器上,他们无法安装 Office 2007,因此不得不安装 Office 2010。在新服务器上,上述事件链导致 workbook.SaveAs() 出错:

使用“1”参数调用“SaveAs”的异常:“Workbook 类的 SaveAs 方法失败” 运行时异常:SaveAs:使用“1”参数调用“SaveAs”的异常:“Workbook 类的 SaveAs 方法失败”在行:180 char:18 + $workbook.SaveAs )

在同一台服务器上,如果我跳过 windows 服务并直接调用 .net exe --calls-> powershell --calls-> excel introp's workbook.SaveAs() 一切正常。

希望我设法解释了这个问题。不确定是什么原因造成的。我已经检查了诸如excel试图保存的文件夹上帐户的权限等内容。

感谢您的帮助

【问题讨论】:

    标签: .net powershell excel-2010


    【解决方案1】:

    不敢相信我花了三天时间解决这个问题!

    非常感谢发布此内容的人:

    http://www.techdecode.com/wp/?p=58

    (来自上面的链接) ・Windows 2008 Server x64

    请创建此文件夹

    C:\Windows\SysWOW64\config\systemprofile\Desktop

    ・Windows 2008 Server x86

    请制作这个文件夹。

    C:\Windows\System32\config\systemprofile\Desktop

    令人沮丧,但已解决!

    【讨论】: