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

  • Question

  • User1325737636 posted

    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?

    Thanks.
     

    Thursday, October 21, 2010 9:49 AM

All replies

  • User552540445 posted

    Hi,

    I also faced the issue few days back, I hope your server contain default printer and no need to install any printer drivers on top of that. Please check the app pool settings in your deployed server. Go to your site app pool and check the Properties of 'Load User Profile' whether it is 'True' or 'False'. If it is false please make it 'True' and Try it.

    Thanks,

    Friday, July 14, 2017 7:42 AM