Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I start an Excel through ASP.NET ?

Status
Not open for further replies.

JCruz063

Programmer
Feb 21, 2003
716
US
Please help!!!

I'm developing an ASP.NET application with C# and I need to create a Microsoft Excel application, add a workbook with a worksheet to it, populate the worksheet with data, save it, and allow the user to download the xls file.

When I run the application, I get the following error:
Access is denied.

And the error is triggered by the following line:
Excel.ApplicationClass app = new Excel.ApplicationClass();

I tried the same code in a Windows aplication (as opposed to Web application) and it runs fine. It appears that the ASPNET user account (in Windows 2000) is perhaps prevented from doing automation in this manner but I went and gave ASPNET administrative rights (again, in Windows 2000) just to see what would happen but the code still fails. Can anyone tell me what I should do?

Thanks

Jose
 
Maybe you can call your Windows application class from ASP.NET (passing whatever data you need).
 
BoulderBum,
I created a class library project and tried calling it from the ASP.NET application and still didn't work! Isn't there a way to tell Windows to allow the ASP user account to create instances of Excel applications?

Jose
 
Did you give the IUSR account execute privilages on the folder housing the Excel stuff?
 
And did you give your assembly enough rights under the .NET security snap-in so that it can run Excel on each user's PC?

Remember -- ASP files by default have very few privledges on a user's PC.

Chip H.


If you want to get the best response to a question, please check out FAQ222-2244 first
 
As the ASP is executed on the server side, the Excel object will be created on the server. So you have to grant rights to execute EXcel application on the server. Check Microsoft .Net Framework Configuration in Start->ControlPanel->Administrative Tools->Microsoft .Net Framework Configuration and the Excel->Properties->Security tab and add {machine}\ASPNET as user.
-obislavu-
 
If you want to open Excel using client side code, then you need to change some browsing settings. I cannot remember off-hand which ones. I have done this in the past with a Word document and it did work.

I actually built up a client-side script on the server and then posted it back to the client, enabling me to still use server-side controls and also to keep the actual logic coding out of the client.
 
Guys,
Microsoft suggests that you do not use server-side automation because it may cause the system to become unstable. As you know, what I'm trying to do is create an Excel application on the server. I read an article from the Microsoft Knowledge Base that discourages such a practice.

jby1 and those of you who have done it, how did the application perform?

Jose

 
Waht you JCruz063 said is right and the big problem with Excel on the server side is when you try to Dispose the Excel object the server is hanging up and creates many problems. Even without ASP , a batch application encounters the same problems.

-obislavu-
 
I agree that it's not a good idea to use MS Excel on the server. I've found a much better solution - SoftArtisans ExcelWriter: I use it to generate Excel reports from my ASP.NET app. The performance is great, and I can include just about anything in the spreadsheet: multiple sheets, formulas, charts, even macros. I like the way it lets me use a formatted template created in Excel and fill it with live data, but you can also create the entire spreadsheet in code.

-Miriam
 
The way I did it performed well, but I was Mail Merging MSWord documents so the performance was never going to be an issue anyway. I think that Miriam's way looks better for this!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top