Avatar of mainrotor
mainrotor
 asked on

I need assistance using Excel in my ASP.Net 3.5 application

Hi Experts,
I have an ASP.Net 3.5 application with VB.Net codebehind.  The application works fine on my machine, but When I deployed it to the Web Server I got the following error:

retrieving the com class factory for component with clsid{00024500-0000-0000-C000-000000000046} failed due to the following error: 80040154

I don't have Excel installed on my the Web Server.  I have included my code so you could see how I use Excel in my application.  Please tell me what's causing this error.

Thanks in advance,
mrotor  


Imports System.Data.OleDb
Imports System.Data
Imports System.Data.SqlClient
Imports System.Runtime.InteropServices


Partial Class BoardReportAutomation
    Inherits System.Web.UI.Page

    Dim objXL As Microsoft.Office.Interop.Excel.Application
    Dim objWkB As Microsoft.Office.Interop.Excel.Workbook
    Dim objSht As Microsoft.Office.Interop.Excel.Worksheet
    Dim objRange As Microsoft.Office.Interop.Excel.Range


Protected Sub cmdFormat_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdFormat.Click



        If Page.IsValid Then
            Try
            'OPEN EXCEL
              objXL = New Microsoft.Office.Interop.Excel.Application
              objWkB = objXL.Workbooks.Open(strExcel)
              objSht = CType(objWkB.Worksheets(1), Microsoft.Office.Interop.Excel.Worksheet)
              objXL.Visible = False

            'DO SOMETHING...

            'Close Excel
              objWkB.Close(False)
              objXL.Quit()
              objWkB = Nothing
              objXL = Nothing


            Catch ex As Exception
                Dim strError As String
                strError = "Error Message: "
                Response.Write("<script language='JavaScript'>alert('" & strError & ex.Message.ToString & "');window.location=self.location;</script>")
                Exit Sub
            End Try
        End If

    End Sub

End Class





ASP.NET.NET ProgrammingVisual Basic.NET

Avatar of undefined
Last Comment
Nasir Razzaq

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Alfred A.

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Mlanda T

I don't have Excel installed on my the Web Server. That there is part of the problem. You are using Excel Automation and that means you MUST have Excel on the server. That is the problem with Excel Automation. The alternative is to try and use a library that allows you to generate Excel files without requiring Excel itself to be installed on the deployment server. There are several options for this. Have a look at these comments I made before:

https://www.experts-exchange.com/questions/26918336/ASP-net-host-and-download-an-Excel-2003-spreadsheet-with-macros.html?cid=1065&anchorAnswerId=35277606#a35277606

you can more easily find lightweight (and open source OR free) libraries to easily manipulate the Excel files: http://www.carlosag.net/Tools/ExcelXmlWriter/, http://simpleooxml.codeplex.com/, http://npoi.codeplex.com/, http://msdn.microsoft.com/en-us/library/aa140066%28office.10%29.aspx
Nasir Razzaq

>  'DO SOMETHING...

What is the code doing there? Is it something that can be done using ADO.NET?

http://support.microsoft.com/kb/316934


This is one commercial alternative which does not require Excel to be installed

http://www.aspose.com/categories/.net-components/aspose.cells-for-.net/default.aspx
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes