Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

.net

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

like image 605
Nag Avatar asked Dec 06 '10 08:12

Nag


2 Answers

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

like image 155
BgRva Avatar answered Sep 18 '22 01:09

BgRva


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.

like image 25
user5045942 Avatar answered Sep 20 '22 01:09

user5045942