Launch an existing excel application from an asp page.
I am trying to call an existing excel application on my server. This application draws a path map for a person's cube location on my bulding floor from the main door. I have written a VB dll which opens the excel application. I am posting the name of the person from one asp page and calling the VBB dll from the next page with the name as a parameter. Somehow the excel application does not get launched on the client browser. Nothing happens on the server console and only a excel.exe process gets created. What do I have to do so as to launch the excel application from the clients browser.
[598 byte] By [
xenon007] at [2007-11-17 13:18:46]

# 1 Re: Launch an existing excel application from an asp page.
Based on your message, you want to draw a map of something in Excel that's installed and supposed to run on a client's system.
I suppose that the DLL you created on the server has something like this:
Dim xl As Excel.Application
Set xl = New Excel.Application
' etc...
When you create a DLL that does something like the above and execute it within an ASP page you do indeed start Excel - as you observed, the Excel application gets created but nothing shows up on your screen. Assuming that you're using default security settings, Excel gets launched in the security context of the ASP - that's the IUSR_?? user on your system (also known as the anonymous account). Whenever a user accesses a web page (or ASP) on your system, Windows reviews the security credentials of the user making the request to determine if it should grant or deny access. By default, all users that request pages from IIS do so as the IUSR_? account (the ? represent the name of your system). As a result, Excel gets launched in that (IUSR_?) user's security context. Chances are that you're not logged on as that user; as a result, you don't see anything on your screen.
The key point to all of this so far is that Excel executes on the Server - not in the user's browser.
If you want to invoke Excel on the user's system by sending some data to their system, having Excel open on the user's desktop, and have it draw a map, you're looking at something that's rather involved. It's possible - I know because I have done it myself - it involves downloading an ActiveX control to the user's system and having the control interact directly with the Server.
An easier approach is to continue with what you started, that is, execute Excel on the server and deliver only the resulting image to the end user. You can automate Excel through your Visual Basic DLL and have it save part of a worksheet as an image. For example, suppose that you want to draw a chart, save it as a GIF image, and present it to the user. The code fragment that follows:
' assumes that the currently selected object is a Chart...
xl.ActiveChart.Export "c:\temp\someChart.gif", "GIF", False
Once you have the chart saved in a file, present it to the user by having an ASP create an IMG link for the above GIF file.
The drawback of doing everything on the Server is that the Server itself becomes the bottleneck of the system. By creating an instance of an Excel application, you're actually creating something referred to as an "out of process component" which works to severely limit the number of users your application can concurrently service. In addition, there's a very good probability that some part of the process could fail while Excel is generating the image - ending up with having several instances of Excel running on the server just taking up system resources. Additionally, there are security issues to deal with since your component needs to be able to read and write to one or more directories - although you can mitigate the system's exposure by making your component a part of an MTS or COM+ application (by giving your component a specific security context to execute in via MTS or COM+, you eliminate the need to elevate the permissions that the IUSR_? account requires thereby reducing how much exposure your system has to anonymous users).
A better approach would be to distribute the workload across the Client and Server. For example, you could generate some data on the server and deliver it to the client as an Excel file without actually having one available on the server. Generate the data from a database, or wherever the data resides on your server, and specify a specific content type to send to the user's system. The listing that follows demonstrates this technique:
<%@ Language=VBScript %>
<%
Response.Buffer = TRUE
Response.ContentType="application/vnd.ms-excel"
Response.Write("This line appears in Excel!")
Response.Flush
%>
The third line, Response.ContentType="application/vnd.ms-excel", indicates that the data that's the server will send to the user's browser should be interpreted using Excel on the client's system. If you save this file as "testXL.asp", for example, and browse to it using your browser, you should see Excel start and have the message "This line appears in Excel!" appear in cell A1.
You can have Excel generate a chart - or whatever - either by having the user use Excel's menu commands manually, have them open some application, or another Workbook, that works with the data that you sent to the user using the above technique. If you work within a trusted environment, you can create an instance of Excel using VBScript or JScript on the client's system and manipulate the data to generate the map on the fly.
Good luck with your project!
Essam Ahmed
___________________________________________________
Author of JScript .NET Programming - Now Avaialble!
http://www.designs2solutions.com/jsnetprg
See how easy it is to:
o migrate from ASP to ASP .NET
o create a Web Service
o consume a Web Service from a Windows Forms app
o work with ADO .NET
o work with ADO in an ASP .NET application
o migrate from ADO to ADO .NET
o ...and more!
o Accepting subscriptions for a newsletter on the .NET Framework and JScript .NET - Subscribe Today!
http://www.designs2solutions.com/jsnetprg
eahmed at 2007-11-9 11:39:12 >

# 4 Re: Launch an existing excel application from an asp page.
What's happening is that Excel put up a message box and is waiting for the user to respond.
When you make changes to an Excel workbook, Excel keeps track of when the workbook was last saved. When you execute the xl.Quit statement, Excel notices that there are some unsaved changes in the workbook and asks if you want to save before exiting using a messge box. Since you invoked Excel in your program you likely won't see the message; as a result, Excel never exits.
You can prevent this problem problem by saving your workbook before calling xl.Quit. If you don't want to save the workbook, trick Excel into thinking that you saved the workbook by setting its Saved property to True, like this:
xl.ActiveWorkbook.Saved = True
xl.Quit
set xl = nothing
I suggest that you set the Saved property to True even if you already saved the workbook, just to ensure that the message box does not pop up.
Essam Ahmed
___________________________________________________
Author of JScript .NET Programming - Now Avaialble!
http://www.designs2solutions.com/jsnetprg
See how easy it is to:
o migrate from ASP to ASP .NET
o create a Web Service
o consume a Web Service from a Windows Forms app
o work with ADO .NET
o work with ADO in an ASP .NET application
o migrate from ADO to ADO .NET
o ...and more
eahmed at 2007-11-9 11:42:16 >
