none
Setting page setup using C# - issue with large excel file RRS feed

  • Question

  • Hi,

    I have an application developed in C#.NET with will merge excel sheets from a number of input excel files and changing the page setup.

    I have used .CopySheet() function to copy the sheet from input to output workbook, then change the below settings for each sheet which copied to output workbook

    PageSetup.PrintTitleRows = "$1:$10"
          PageSetup.CenterFooter = "Page &P of &N";

    When there is a huge number of input files (more than 1000), I am getting errors as below. But some times it will work as expected. And sometimes I got error #1  and sometime error #2.

    1. Unable to set the CenterFooter property of the page setup class.

    2. Exception from HRESULT: 0x800A03EC

    Please help me.

    Thanks in advance,

    Ramesh

    Tuesday, September 16, 2014 5:08 AM

All replies

  • It's pretty hard to guess what is actually going on here but first I would add a try/catch block in your C# code to check the Active Printer.

    See details: http://support.microsoft.com/kb/291298

    Tuesday, September 16, 2014 7:20 AM
  • Thanks Michal.

    I already found this, but as this error is not occuring on every run, I have not checked this.

    I will try this and update you.

    Meantime, I am running this applicaiton as a windows service in Windows 2003 server. On that machine, I am not able to set the default printer. Is this make any sense?

    Thanks,

    Ramesh

    Tuesday, September 16, 2014 7:28 AM
  • Hi,

    >>Meantime, I am running this applicaiton as a windows service in Windows 2003 server. On that machine, I am not able to set the default printer. <<

    Do you mean that you are doing Office automation in a Windows server without a printer installed?

    If so, as @Michal Krzych mentioned, you cannot use page setup properties in Excel if no printers were installed.

    In addition, Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment. (From Considerations for server-side Automation of Office)

     

     


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, September 17, 2014 7:14 AM
    Moderator
  • Thanks Luna.

    There was some printer installed on the server like "Adobe PDF", "Office Document Image Writer" etc. But I am  not able to set default printer. I am not sure whether I have permissions to do so.

    The error occured sometimes only, that make me confusing.

    I have tried "OpenXML" to replace this functionality and not able to copy the sheets styles properly. So I created the windows service for excel functionalities.

    Thanks,
    Ramesh

    Wednesday, September 17, 2014 7:28 AM
  • >>The error occured sometimes only, that make me confusing.<<

    I'm not sure whether the first error is related to none default printer, but Office may exhibit unstable behavior and/or deadlock when Office is run in Windows server, so the issue will occured sometimes.

    >>I have tried "OpenXML" to replace this functionality and not able to copy the sheets styles properly. <<

    Cell styles in OpenXML spreadsheet (SpreadsheetML)

    Friday, September 19, 2014 8:11 AM
  • Thanks.

    I think this is something related to user. I am able to work this in another server.

    When I checked, I am not able to set the default printer even manually in the server, where the error occured. But in the new server, I am able to change the default server.

    I am in 'Administrator' group on both machines.

    I will check the OpenXML sample you give. (I tried many methods already)

    Thanks,
    Ramesh.

    Friday, September 19, 2014 8:28 AM