Solved

Excel and .net WebService issue

Posted on 2007-04-11
3
674 Views
Last Modified: 2013-12-17
I have written a Web Service in C# using visual studio 2005. One of the functions is to generate reports using MS excel. The problem I have is the following.

While I am debugging the web service (running it directly from VS), the report generation works properly. If I publish the web service and run the report generation it fails with the following error.
"Unable to set the PrintTitleRows property of the PageSetup class".
I have made sure all of the Interop DLL's (e.g. Interop.Excel.dll etc) are copied to the remote web server as well as the same version of MS office being installed as on the development machine (2003 professional).

I have even installed VS2005 and debugged the application on the remote server. The report generation works when the Web Service is run from VS but failed when published.

As anyone got any idea as to what is going on here?


Sample of the code:
    Excel.ApplicationClass excelApp;
    Excel.Workbook newWorkbook;
    excelApp = new Excel.ApplicationClass();

    Excel._Worksheet oSheet;
    Excel.Range oRng;
    excelApp.Visible = false;
    newWorkbook = excelApp.Application.Workbooks.Add(Type.Missing);
    oSheet = (Excel._Worksheet)newWorkbook.ActiveSheet;
    oSheet.Name = RepFormat.ReportReference;
    oSheet.PageSetup.PrintTitleRows = "$1:$3";    // This line fails





0
Comment
Question by:WallaceAdrian
  • 2
3 Comments
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 18888556
I suspect that the problem is that the account your service is running under does not have printers installed. As a result you cannot access anything to do with PageSetup.
Regards,
Rory
0
 
LVL 2

Author Comment

by:WallaceAdrian
ID: 18888644
Hi Rory,
Your suggestion makes sense but I have just tried that but I get the same result.

I went in to the printer properties for the default printer. On the security tab, I added the NETWORK SERVICE account and gave all priveledges (Print, Manage printers & documents ...).
I also stopped and restarted the service.

Is this what you had in mind?

Thanks
0
 
LVL 85

Accepted Solution

by:
Rory Archibald earned 500 total points
ID: 18888693
No - Office apps work on the basis that they are being run interactively with the desktop - i.e. you are logged in as the account they are running as. If the *profile* for the account that is running the service does not have an installed printer, then you cannot access the PageSetup properties. If your service is running as a network/system account, then it does not have a profile or any installed printers. Can you run it as a user account?
Regards,
Rory
PS You may wish to review this article: http://support.microsoft.com/?id=257757
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question