Reputation: 61
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
Upvotes: 6
Views: 12960
Reputation: 21
Check "default printer" in "Devices and Printers" page.
If any (redirected) printer is default change it. Default printer must not be any "redirected" one.
Upvotes: 2
Reputation: 21
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.
Upvotes: 2
Reputation: 3043
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:
Upvotes: 1
Reputation: 1551
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
Upvotes: 6