ExportAsFixedFormat与Excel失败

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

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

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

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挂起而不是立即抛出exception。

我出于想法,并感谢任何帮助。

您必须为此用户select默认打印机。 尝试将以下代码导入到您的registry中。 注意:将这些打印机replace为您自己的(虚拟)打印机。

 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:" 

当然,你仍然需要创build你的桌面文件夹

 C:\Windows\SysWOW64\config\systemprofile 

或中

 C:\Windows\System32\config\systemprofile 

取决于你的设置。

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

错误:

[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:"

我强烈地挣扎着,这个post非常接近。 在尝试了一些其他的东西之后,我知道这篇文章很贴切,并且认为我会尝试一些东西。

为了logging,在我们运行Windows Server 2008 R2和Excel 2013自动化时,systemprofile中的“Desktop”文件夹修复了此问题。 这只是我们升级到Windows Server 2012 R2和Excel 2016之后才出现的一个问题。为了消除Excel作为罪魁祸首,我尝试了使用Windows Server 2012 R2和Excel 2013的服务器,并且遇到了非常类似的问题。

networking服务下的所有自动化工作都很好,但理想情况下,我们希望在ApplicationPoolIdentity下运行我们的网站。

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

 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这是我find的信息。

 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中的应用程序身份安全标识符。 这将是一个非常长的字母数字虚线,如“S-1-5 – ## – ######### – ######### – ######## ## – ######### – #########”

不像上面的答案,这是我需要在registry中编辑的用户。

所以现在按照上面的答案,我不得不将以下添加到registry。 注意:将键添加到S-1-5-18中并没有解决问题,我不得不将它们添加到上面find的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选项不适合我。

希望这可以节省一些人有一天狩猎的麻烦。