Problem on the ASP using the Excel.Application Object

D

David Huang

Hi, All:
I want to use excel component in the ASP.
My code is that
-----------------------------------------------------------
Dim oExcel As Object
Dim oBook As Object
Dim oSheet As Object

'Start a new workbook in Excel
Set oExcel = CreateObject("Excel.Application")
Set oBook = oExcel.Workbooks.Add

'Add headers to the worksheet on row 1
Set oSheet = oBook.Worksheets(1)
oSheet.Range("A1:C1").Value = Array("ORD0001", "Amount", "Tax")

'oSheet.Range("A2:A100").
oSheet.Range("A1").FormatConditions.Add(xlCellValue, xlEqual,
"ORD0001").Font.Bold = True


'Save the Workbook and Quit Excel
oBook.SaveAs "C:\Book1.xls"
oExcel.Quit
-------------------------------------------------------
But the function FormatConditions seems no use.


So I test this code in Visual Basic 6.0. I find the error is that

oSheet.Range("A1").FormatConditions.Add(xlCellValue, xlEqual,
"ORD0001").Font.Bold = True

Run-time error 5: invalidate procedure call or argument


Then I open the menu Project -> Preference, and add the "Microsoft Excel
10.0 Object Library".


Then the visual basic code could run successfully.

---------------------------------------------------------
My question is that.
How to make the ASP code run ?
How to add the "Microsoft Excel 10.0 Object Library" in asp using the above
code?

Thanks
 
B

Bob Barrows

David said:
Hi, All:
I want to use excel component in the ASP.
My code is that
-----------------------------------------------------------
Dim oExcel As Object
Dim oBook As Object
Dim oSheet As Object

'Start a new workbook in Excel
Set oExcel = CreateObject("Excel.Application")
Set oBook = oExcel.Workbooks.Add
Then I open the menu Project -> Preference, and add the "Microsoft
Excel
10.0 Object Library".


Then the visual basic code could run successfully.

---------------------------------------------------------
My question is that.
How to make the ASP code run ?
How to add the "Microsoft Excel 10.0 Object Library" in asp using the
above code?

Excel would need to be installed on the server, for one thing.

For another, MS does not recommend automating Office applications from
server code:
http://support.microsoft.com/default.aspx?scid=kb;en-us;257757

HTH,
Bob Barrows
 
D

David Huang

I have seen this article.
My problem is that the server is W3K, Excel 2000, IIS5 installed.
How to use the correct type library in the ASP.
 
B

Bob Barrows

David said:
I have seen this article.
My problem is that the server is W3K, Excel 2000, IIS5 installed.
How to use the correct type library in the ASP.
If the correct version of Excel is installed on the server, then the
createobject line is all you need. If there are multiple versions of Excel
installed on the server, then you will have a problem. You can try using

Set oExcel = createobject("Excel.Application.10")

I suggest you create a VB dll to do whatever you are doing with Excel here.

BTW, you have the following Dim statments in your example code which you say
you tried in ASP:

Dim oExcel As Object
Dim oBook As Object
Dim oSheet As Object

You do realize that all variables are Variant in scripting. The "As Object"
parts of these lines should raise an error in vbscript.

Bob Barrows
 
R

roger

But the function FormatConditions seems no use.

Does this work?

dim x

set x = oSheet.Range("A1").FormatConditions.Add(xlCellValue, xlEqual, >
"ORD0001")

x.Font.Bold = True
 
D

David Huang

Thanks All:
I have finished this issue with add the follow code in the global.asa.

<!-- METADATA TYPE="TypeLib"
UUID="{00020813-0000-0000-C000-000000000046}" -->


But the VERSION symbol I couldn't add in the code because it cause the
bug. I don't know why because the VERSION is refered in the spec.

With the new code, the ASP will find the newest version in the server
side
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top