View Full Version : Getobject() on Excel.application fail in ASP, why?

09-05-2004, 05:12 AM
Dear Sir:
I am developing a web application with "ASP--COM--Database" structure.
The COM is a activeX DLL developed in VB6.0, in this COM I need open Excel application: If there is not a running Excel instance, Create it with CreateObject(); if there is already a running Excel instance, Get it with Getobject(). Here is the simplified code in VB Code:
Dim xlsApp As New Excel.Application
Public Function GetExcelAPP() As String
Dim tmp$
On Error Resume Next
Set xlsApp = GetObject(, "Excel.Application")
tmp = xlsApp.Name 'test if a true application is got
If Err.Number <> 0 Or xlsApp Is Nothing Then
GetExcelAPP = "false"
'no running excel,create ......
GetExcelAPP = "true"
End If
End Function

In my develop computer(WIN2000) everything is fine, but in product computer(WIN2000 too) If I call the DLL function from .ASP it will fail.
(Note:I have launch excel application in advanced from desktop)

dim myObject
set myObject=server.createobject("myDLL.myClass")
response.write myObject.GetExcelAPP() 'I get "false"

I try to call the DLL function from VB Form,found it will success:
Private Sub Command1_Click()
Dim a As New myDLL.myClass
MsgBox a.GetExcelAPP 'I get "true"
End Sub

I think maybe it is relative to IIS anonymous permission, So I change IIS anonymous to Administrator, but it still failed in ASP.

Can anyone help me? Thanks advanced.

2004 9 5

09-05-2004, 11:18 AM
Debug by temporarily setting the return of the function to error description and not to "false" to get an idea what's going on.

If Err.Number <> 0 Or xlsApp Is Nothing Then
'GetExcelAPP = "false"
GetExcelAPP = "Error " & Err.Number & ":" & Err.Description
'no running excel,create ......
GetExcelAPP = "true"
End If

09-05-2004, 11:30 AM
Yes, you are right.
The error say "Error 429:ActiveX component can't create object"


09-05-2004, 10:27 PM
bhguo: What are you trying to accomplish on the user's end in Excel? Depending on your answer, there may be a simplier way to do what you want.

09-06-2004, 07:51 AM
Did you launch the Excel from the desktop of the IIS server's machine? This is what you're supposed to do. Looks like you launched the Excel from the client's machine but of course, I may be wrong. :D

09-06-2004, 03:06 PM
I do launch excel application from the desktop of the IIS server's machine, I am debugging on IIS machine. What make me confused is:If I call the DLL function from VB Form it works fine, If I call it through from .ASP it fails, and I try to change IIS anonymous to Administrator, no effect.

There are 2 function I want to use excel on the server side:
(1) The Export function
User can export what he searched on web page to client as excel file, so when user submit a export request from IE( a button on webpage), the server side will create a temporary excel file, search the requested data from Database and write the data into the file, then download the excel file to client(IE).
(2) The Report function
I hope utilize the excel's pivottable to analyze data, produce chart gif, to make report.

All these should be done on server side.


09-06-2004, 03:17 PM
By the way, If the Getobject() cannot work, I have to Createobject() every time I need excel application, the shortcoming is it will waste lot of server resource , because the startup and shutdown of excel apllication is a very heavy task. These is what i am using on product machine.

09-06-2004, 08:26 PM
You can accomplish #1 way more efficiently by streaming an html table with your data in it and change the ContentType to "application/vnd.ms-excel".

Response.ContentType = "application/vnd.ms-excel"
your data table in html goes here


This shows you how to insert fomuli into the excel sheet:


As far as charts go, I think using OWC on the server might be more efficient.


Search for "application/vnd.ms-excel ASP" and "OWC ASP" on Google for alot more info.

09-07-2004, 08:55 AM
Thanks a lot for your suggestion, a good idea.
I don't known the OWC can be used to produce Excel file and chart gif, I will try it and distribute the result as soon as I finish. Thanks.


09-10-2004, 03:05 PM
About OWC solution, I found it's main purpose is to show data in Client, so it's not versitile as excel application. for example:
When filling data into a sheet, I use CopyFromRecordset with excel application, like this: xlsSheet.Range("A2").CopyFromRecordset rstData. OWC doesn't support this method, in OWC we have to fill data with .Cells(i,j).value = value, which is very slow.
Another, OWC is difficult to modify Sheet name, to maintain(add,delete etc.) multiple sheets in a single excel file. As my product's growth, maybe it's required to pruduce a perfect Export file in which inlude multiple sheets.

So, I will use the excel automation solution at present, CreateObject() for excel application every time I need use it, once finished, close it.

Any way, thank you for your help.