开发者

ExportAsFixedFormat with Excel fails

开发者 https://www.devze.com 2023-01-29 16:41 出处:网络
I try to convert Excel files to PDF via COM automation. The code runs as a service using the sy开发者_如何学Gostem user. Unfortunately, I get the error \"0x800A03EC\" in the ExportAsFixedFormat() func

I try to convert Excel files to PDF via COM automation. The code runs as a service using the sy开发者_如何学Gostem user. Unfortunately, I get the error "0x800A03EC" in the ExportAsFixedFormat() function. It works when I run this in an interactive session.

I've heard the systemprofile needs a Desktop folder, so I added those.

I've heard this also might have to do with the system user not having a default printer, so I added values to the following keys:

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

But this only makes Excel hang instead of throwing an exception immediately.

I'm out of ideas and thankful for any help.


You have to select a default printer for this user. Try to import following code into your registry. Note: Replace these printers for your own (virtual) printers.

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

Of course you still have to create your Desktop folder in

C:\Windows\SysWOW64\config\systemprofile

or in

C:\Windows\System32\config\systemprofile

depending on your setup.

After these steps you should be able to export Word, Powerpoint and Excel to PDF by using a regular, non-interactive service (e.g. Windows NT/SYSTEM user). You don't need any alterations in your Component Services


Wrong:

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

Correct:

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


I struggled with this mightily and this post was so close. After trying a number of other things I knew this post was close and thought I'd try something.

For the record, the "Desktop" folder fix in systemprofile fixed this issue when we were running Windows Server 2008 R2 and Excel 2013 Automation. This only started being an issue for after we upgraded to Windows Server 2012 R2 and Excel 2016. To eliminate Excel as the culprit, I tried on a server with Windows Server 2012 R2 and Excel 2013 and experienced very similar issues.

All automation worked just fine under Network Service, but ideally, we wanted to run our site under ApplicationPoolIdentity.

First things first, the application pool running with ApplicationPoolIdentity needs to Load the User Profile.

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

So now I had to figure out who this identity was. Maybe there's a better way to do this, but since I added the user to IIS_IUSRS this is where I found the information.

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

Now you should see as a Member of IIS_IUSRS IIS APPPOOL\ (SID) where SID is your applicationpoolidentity security identifier in windows. This will be a very long alpha-numeric dashed string like "S-1-5-##-#########-#########-##########-#########-#########"

Unlike the answers above, this was the user I needed to edit in the registry.

So now following the above answers I had to add the following to the registry. Note: Adding the keys to S-1-5-18 did not solve the issue, I had to add them to the SID of the ApplicationPoolIdentity found above.

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

Notice how I used the "Correct" response from eletre/Robert. Using the OneNote option for Device did not work for me.

Hopefully this saves someone the trouble of hunting this down some day.

0

精彩评论

暂无评论...
验证码 换一张
取 消