Excel

Discussion in 'ASP.NET 2.0' started by jesusjones, Aug 24, 2007.

  1. Hi, i'm trying to open an excel file, use it as template and save a new file with some data... however everytime i get this error
    Error: Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80040154.

    this is the code... thanks in advance...

    Excel.Application oXL;
    Excel._Workbook oWB;
    Excel._Worksheet oSheet;


    try
    {
    GC.Collect();// clean up any other excel guys hangin' around...
    oXL = new Excel.Application();

    oXL.Visible = false;
    //Get a new workbook.
    oWB = oXL.Workbooks.Add(System.Reflection.Missing.Value);
    oWB = (Excel._Workbook)(oXL.Workbooks.Open('template.xls', 0, true, 5,
    '', '', true, Excel.XlPlatform.xlWindows, '\t', false, false, 0, true, true, true));

    oSheet = (Excel._Worksheet)oWB.Sheets.get_Item(1);
    //get our Data

    // Create Header and sheet...
    int iRow = Start + 1;
    for (int j = 0; j < vals.Count; j++)
    {
    Hashtable temp = (Hashtable)vals[j];
    ArrayList keys = new ArrayList(temp.Keys);
    keys.Sort();
    foreach (int k in keys)
    {
    oSheet.Cells[iRow, k] = temp[k].ToString();
    }
    iRow++;
    }

    oXL.Visible = false;
    oXL.UserControl = false;
    string strFile = 'report' + System.DateTime.Now.Ticks.ToString() + '.xls';
    oWB.SaveAs(strCurrentDir + 'rep\\' + strFile, Excel.XlFileFormat.xlWorkbookNormal,
    null, null, false, false, Excel.XlSaveAsAccessMode.xlShared, false, false, null, null, null);

    // Need all following code to clean up and extingush all references!!!
    oWB.Close(null, null, null);
    oXL.Workbooks.Close();
    oXL.Quit();

    System.Runtime.InteropServices.Marshal.ReleaseComObject(oXL);
    System.Runtime.InteropServices.Marshal.ReleaseComObject(oSheet);
    System.Runtime.InteropServices.Marshal.ReleaseComObject(oWB);
    oSheet = null;
    oWB = null;
    oXL = null;
    GC.Collect(); // force final cleanup!
    string strMachineName = Request.ServerVariables['SERVER_NAME'];
    lStatus.Text = '<A href=' + System.Configuration.ConfigurationManager.AppSettings['root'] + 'rep/' + strFile + '>Download</a>';

    }
    catch (Exception theException)
    {
    lStatus.Text = theException.ToString();
    }
     
  2. The COM object your application is trying to use needs installation on the server.This object is not supported.

    Vikram

    DiscountASP.NET
    www.DiscountASP.NET
     
  3. Thanks for the info... I suspected that... I had to fix it creating a client side script...
     

Share This Page