Home » Asp.net

Excel Automation: Unable to set the Orientation property of the PageSetup class

I have a web application that generates various reports in Excel or in Word and then downloads them to the client where they can be printed.  Even though there is nothing being printed on the web server, I want to properly format the reports in terms of page orientation, etc.  Everything is working great with Word.

In Excel, whenever I try to change the page orientation to Landscape I get:

COMException (0x800a03ec): Unable to set the Orientation property of the PageSetup class

The single line of code that is causing this is:

mySheet.PageSetup.Orientation = Microsoft.Office.Interop.Excel.XlPageOrientation.xlLandscape;

If I comment out the line everything else works like a champ.  The code also works fine when I test it on my local computer (without the line commented out).

On the server, the web application runs with the username CCSUser.  I can log onto the server using that username, bring up Excel manually, create some sort of spreadsheet, and set the orientation of that spreadsheet to Landscape.  It works fine.  It just does not work when I try to do it from my C# code.

There is no physical printer attached to the server.  The default printer for the account used by the web application is Microsoft XPS Document Writer.  The security permissions on that printer allow me to Print, Manage the Printer, and Manage Documents.

We had the same problem before our recent upgrade from Windows Server 2000 to 2008.  I had hoped that it might magically go away when we upgraded.  It didn't.

What am I doing wrong?


<< Previous      Next >>

Microsoft   |   Windows   |   Visual Studio   |   Sharepoint   |   Azure