views:

593

answers:

2

I have a ASP.NET application that allows users to export their staff's absences each month to Microsoft Excel. The application is currently generating the following exception

Exception: Cannot create ActiveX component.

with the following stack trace

System.Exception: Cannot create ActiveX component. at Microsoft.VisualBasic.Interaction.CreateObject(String ProgId, String ServerName) at HR.ManagerSummary.ExportToExcel() in H:\Development\pagec\Visual Studio 2005\Projects\HR\ysnet2\Time\ManagerSummary.aspx.vb:line 935 at HR.ManagerSummary.btnExcel_Click(Object sender, EventArgs e) in H:\Development\pagec\Visual Studio 2005\Projects\HR\ysnet2\Time\ManagerSummary.aspx.vb:line 891 at System.Web.UI.WebControls.Button.OnClick(EventArgs e) at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

The code fails at the CreateObject line.

    'Create the Excel object
    Dim objXL As Object = CreateObject("Excel.Application") ' New Microsoft.Office.Interop.Excel.Application
    Dim objWB As Object = objXL.Workbooks.Add
    Dim objWS As Object = objWB.Worksheets(1)

I've set permission in DCOM Config for Microsoft Excel Application for the IUSR_ account but that has not resolved the issue. Any ideas would greatly be appreciated.

Cheers

James

A: 

Did you registered the ActiveX on the server?

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

rjlopes
A: 

SpreadsheetGear for .NET will let you save xls and xlsx workbooks directly to a response stream with IWorkbook.SaveToStream. It is all safe managed C# code so there is no need to run anything as admin and you will not run into the problems that Excel COM Interop bring on an ASP.NET server.

You can see some simple ASP.NET Excel Reporting samples (C# and VB) using SpreadsheetGear here and download the free trial here if you want to try it yourself.

Disclaimer: I own SpreadsheetGear LLC

Joe Erickson