Unable to set the Orientation property of the PageSetup class in Excel Program

StackOverflow https://stackoverflow.com/questions/4364345

  •  09-10-2019
  •  | 
  •  

Question

I have written following code in .Net

excel = New Excel.Application
wBook = excel.Workbooks.Add()
wSheet = wBook.ActiveSheet()
wSheet.PageSetup.Orientation = XlPageOrientation.xlLandscape

When i run this from local sytem it is working and when i copy this to a server and will be run from a service giving following error.

Unable to set the Orientation property of the PageSetup class

No correct solution

OTHER TIPS

The PageSetup class of Excel must interact with the printer drivers on the server. If there are no printer drivers installed or access to them is restricted, any calls to this class with throw an exception.

You should ensure a default printer is set on the server and there are printer drivers installed. Also, if you are accessing this from ASP.net there are access issues and you should ensure the ASP.Net account has permission to access the printer. See this article which lays out some of the issues in more detail: http://support.microsoft.com/?id=291298

In general, if you are using Office 2007 or later you should avoid server-side automation as this can create unstable behavior - use the Open XML formats if possible. See http://support.microsoft.com/kb/257757

I'm not sure if you are doing ASP.net application. But here's what I got.

I have a ASP 4.0 and my code basically generate an excel file. Once excel file is generated, I export that to be a pdf. That's causing the same issue u had.

The way to resolve it is to set the Load User Profile to true It's under AppPool. right clicking it and you will see this property.

As BgRva pointed out, you need to install printer drivers. The PageSetup class of Excel must communicate with the printer drivers

I'm having similar issue running related code on Windows 8 operating under Mac Parallels (Virtual Machine). For anyone who are doing Visual Studio deployment on Mac Parallels, here's what I'm doing:

  1. Disable Printers sharing between Mac and Windows. Go to Parallels (VM) > Configure > Hardware and click Print. Uncheck 'Add all Mac printers' and 'Synchronize Default Printer'
  2. Install printer's driver on Windows
  3. In order to get assigned IP address by the same wireless router (if you need to connect to printer wirelessly), you need to set up networking as bridged. Go to Parallels (VM) > Configure > Hardware > 'Network 1' and choose Networking type as Airport and DHCP server as Auto

Check "default printer" in "Devices and Printers" page.

If any (redirected) printer is default change it. Default printer must not be any "redirected" one.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top