Solved

Excel and .net WebService issue

Posted on 2007-04-11
3
672 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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,…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

896 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now