【问题标题】:ExportAsFixedFormat with Excel fails使用 Excel 的 ExportAsFixedFormat 失败
【发布时间】:2011-05-23 10:52:32
【问题描述】:

我尝试通过 COM 自动化将 Excel 文件转换为 PDF。该代码使用系统用户作为服务运行。不幸的是,我在 ExportAsFixedFormat() 函数中收到错误“0x800A03EC”。当我在交互式会话中运行它时它可以工作。

我听说系统配置文件需要一个桌面文件夹,所以我添加了这些。

我听说这也可能与系统用户没有默认打印机有关,所以我在以下键中添加了值:

HKEY_USERS\S-1-5-18\Software\Microsoft\Windows NT\CurrentVersion\Devices
HKEY_USERS\S-1-5-18\Software\Microsoft\Windows NT\CurrentVersion\PrinterPorts

但这只会让 Excel 挂起,而不是立即抛出异常。

我没有想法,感谢您的帮助。

【问题讨论】:

  • 您检查了服务设置 -> 登录选项卡“允许服务与桌面交互”?

标签: excel com automation


【解决方案1】:

您必须为此用户选择默认打印机。尝试将以下代码导入您的注册表。注意:将这些打印机替换为您自己的(虚拟)打印机。

Windows Registry Editor Version 5.00

[HKEY_USERS\S-1-5-18\Software\Microsoft\Windows NT\CurrentVersion\Devices]
"Send To OneNote 2010"="winspool,nul:"
"Microsoft XPS Document Writer"="winspool,Ne00:"

[HKEY_USERS\S-1-5-18\Software\Microsoft\Windows NT\CurrentVersion\PrinterPorts]
"Send To OneNote 2010"="winspool,nul:,15,45"
"Microsoft XPS Document Writer"="winspool,Ne00:,15,45"

[HKEY_USERS\S-1-5-18\Software\Microsoft\Windows NT\CurrentVersion\Windows]
"UserSelectedDefault"=dword:00000000
"Device"="Send To OneNote 2010,winspool,nul:"

当然你还得在

中创建你的桌面文件夹
C:\Windows\SysWOW64\config\systemprofile

或在

C:\Windows\System32\config\systemprofile

取决于您的设置。

完成这些步骤后,您应该能够使用常规的非交互式服务(例如 Windows NT/SYSTEM 用户)将 Word、Powerpoint 和 Excel 导出为 PDF。您不需要对组件服务进行任何更改

【讨论】:

  • 我在此期间发现了这一点,但既然你已经回复了,那就是奖金。
【解决方案2】:

错误:

[HKEY_USERS\S-1-5-18\Software\Microsoft\Windows NT\CurrentVersion\Windows] "UserSelectedDefault"=dword:00000000 "Device"="Send To OneNote 2010,winspool,nul:"

正确:

[HKEY_USERS\S-1-5-18\Software\Microsoft\Windows NT\CurrentVersion\Windows] "UserSelectedDefault"=dword:00000000 "Device"="Microsoft XPS Document Writer,winspool,Ne00:"

【讨论】:

    【解决方案3】:

    我为此苦苦挣扎,而这篇文章是如此接近。在尝试了一些其他的事情之后,我知道这篇文章很接近了,我想尝试一下。

    作为记录,当我们运行 Windows Server 2008 R2 和 Excel 2013 自动化时,systemprofile 中的“桌面”文件夹修复修复了这个问题。这只是在我们升级到 Windows Server 2012 R2 和 Excel 2016 后才开始出现的问题。为了消除 Excel 作为罪魁祸首,我在装有 Windows Server 2012 R2 和 Excel 2013 的服务器上进行了尝试,并遇到了非常相似的问题。

    所有自动化在 Network Service 下运行良好,但理想情况下,我们希望在 ApplicationPoolIdentity 下运行我们的网站。

    首先,使用 ApplicationPoolIdentity 运行的应用程序池需要加载用户配置文件。

    Start Run -> inetmgr
    expand Server -> Application Pools
    right click on your App Pool -> Advanced Settings
    under Process Model -> Load User Profile <-- should be set to true
    

    所以现在我必须弄清楚这个身份是谁。也许有更好的方法可以做到这一点,但由于我将用户添加到 IIS_IUSRS,因此我在此处找到了信息。

    Windows -> Edit local users and groups
    Groups -> right click IIS_IUSRS -> Add to Group...
    Add...  
    Locations... (choose local server), click OK
    In the Enter the object names to select box type IIS APPPOOL\<app pool name>
      (note the space and the triple P)
      also, <app pool name> is the name of your Application Pool in inetmgr
    

    现在您应该将其视为 IIS_IUSRS IIS APPPOOL\ (SID) 的成员,其中 SID 是您在 Windows 中的 applicationpoolidentity 安全标识符。这将是一个很长的字母数字虚线字符串,例如 "S-1-5-##-#########-#########-######## ##-#########-#########"

    与上面的答案不同,这是我需要在注册表中编辑的用户。

    所以现在按照上述答案,我必须将以下内容添加到注册表中。注意:将密钥添加到 S-1-5-18 并不能解决问题,我必须将它们添加到上面找到的 ApplicationPoolIdentity 的 SID。

    [HKU]\SID\Software\Microsoft\Windows NT\CurrentVersion\Devices
      "Send To OneNote 2010"="winspool,nul:"
      "Microsoft XPS Document Writer"="winspool,Ne00:"
    [HKU]\SID\Software\Microsoft\Windows NT\CurrentVersion\PrinterPorts
      "Send To OneNote 2010"="winspool,nul:,15,45"
      "Microsoft XPS Document Writer"="winspool,Ne00:,15,45"
    [HKU]\SID\Software\Microsoft\Windows NT\CurrentVersion\Windows
      "UserSelectedDefault"=dword:00000000
      "Device"="Microsoft XPS Document Writer,winspool,Ne00:"
    

    请注意我是如何使用 eletre/Robert 的“正确”响应的。对设备使用 OneNote 选项对我不起作用。

    希望这可以省去某天追捕这个问题的麻烦。

    【讨论】:

      猜你喜欢
      • 2017-05-29
      • 1970-01-01
      • 2016-06-21
      • 1970-01-01
      • 2021-06-28
      • 2017-07-12
      • 2016-06-01
      • 1970-01-01
      • 2016-07-28
      相关资源
      最近更新 更多