Cannot set the Orientation property of the PageSetup class in Excel

I wrote the following code in .Net

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

When I start it from the local system, it works and when I copy it to the server and start from the service providing the following error.

Unable to set the Orientation property of the PageSetup class

+4
source share
4 answers

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

You must ensure that the default printer is installed on the server and the printer drivers are installed. In addition, if you access this from ASP.net, there are access problems, and you must ensure that the ASP.Net account has permission to access the printer. See this article for some of the questions 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 lead to unstable behavior - if possible, use Open XML formats. See http://support.microsoft.com/kb/257757

+5
source

I am not sure if you are using ASP.net application. But here is what I got.

I have ASP 4.0, and my code basically generates an excel file. After creating the excel file, I export it to pdf. This causes the same problem as yours.

The way to solve the problem is to install. Load the user profile to true. This is under AppPool. by right-clicking and you will see this property.

+2
source

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

I have a similar problem with running related code in Windows 8 running under Mac Parallels (Virtual Machine). For those who are deploying Visual Studio on Mac Parallels, here's what I do:

  • Disable printer usage between Mac and Windows. Go to Parallels (VM)> Configure> Hardware and click Print. Uncheck "Add all Mac printers and" Sync default printer "
  • Install the printer driver in Windows
  • To get the assigned IP address with the same wireless router (if you need to connect to the printer wirelessly), you need to configure the network as a bridge. Go to Parallels (VM)> Configure> Hardware> "Network 1" and select "Network Type" as "Airport" and "DHCP Server" as "Auto"
+1
source

Check the "default printer" on the "Devices and Printers" page.

If any (redirected) printer changes it by default. The default printer should not be "redirected".

0
source

All Articles