locked
Excel in ASP.NET RRS feed

  • Question

  • User355892953 posted

    Hi,

    I'm trying too use the Excel interop in a ASP application. I now this is not the most correct option and I should use VSTO but that's not possible for me.

    My problem is that when I do:

        Application oExcel = new Application();

    I receive the following error:

        Retrieving the COM class factory for component with CLSID failed due to the following error: 80070005.

    I googled and I found that I need to change the permissions in the DCOMCNFG.

    This works in XP and 2003 server but not in Vista!

    Any help?
     

    Cheers

    Agapito

    Wednesday, December 19, 2007 7:09 AM

Answers

All replies

  • User-1567482218 posted


    If all you need to do is generate an Excel sheet programatically, take a look at this article - http://eggheadcafe.com/tutorials/aspnet/6e1ae1a8-8285-4b2a-a89b-fafc7668a782/aspnet-download-as-wor.aspx

    The technique that is described doesn't need any components to be installed & works with just HTML, CSS & Office XML

    Thursday, December 20, 2007 5:09 AM
  • User355892953 posted

    The problem is that I need to edit a .xls file. I don't want to create a xls.

    I have the excel template and I need to fill in the values. 


    Thursday, December 20, 2007 7:42 AM
  • User113421904 posted

    Hi Agapito,

    Hope this helps:
       
    How to automate Microsoft Excel from Microsoft Visual C# .NET
     
    http://support.microsoft.com/kb/302084

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, December 25, 2007 12:52 AM
  • User1485388733 posted

    //Change the Source File's Extension to ".xml" because we are about to use OpenXML method in this function. You can even use Open() method for .txt, .csv, etc files.

    //This function takes an "xml" file (even if the contents in the file are html/csv contents) and converts into a Binary Excel File.

    //Idea is very simple, Open a file and Save As a binary file.

    public
    void ExportToExcel()

    {

     

    try

    {

    string xmlFile = "C:\\test.xml";

    string xlsFile =  "C:\\test.xls";

    Microsoft.Office.Interop.Excel.Application oApp = new Microsoft.Office.Interop.Excel.Application();

    System.Diagnostics.Process[] processes = System.Diagnostics.Process.GetProcessesByName("Excel");

    System.Diagnostics.Process currentProcess = processes[processes.Length - 1];//Get the Last Excel process just created (a bit tricky)

     

    oApp.DisplayAlerts =
    false;

    object obj = oApp.Workbooks.OpenXML(xmlFile, System.Reflection.Missing.Value, System.Reflection.Missing.Value);

    object[] para = new object[12];

    object fileName = xlsFile;

    object fileFormat = Microsoft.Office.Interop.Excel.XlFileFormat.xlExcel5;

    object missing = System.Reflection.Missing.Value;

    object fileMode = Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive;

    para[0] = fileName;

    para[1] = fileFormat;

    para[2] = missing;

    para[3] = missing;

    para[4] = missing;

    para[5] = missing;

    para[6] = fileMode;

    para[7] = missing;

    para[8] = missing;

    para[9] = missing;

    para[10] = missing;

    para[11] = missing;

    Type MyType = (Type)(obj.GetType());MyType.GetMethod("SaveAs").Invoke(obj, para);

    oApp.Workbooks.Close();

    oApp.Quit();

     

    currentProcess.Kill();

     

     

     

    }

    catch (Exception ex)

    {

    throw ex;

    }

    }

    Wednesday, July 2, 2008 9:26 AM
  • User-850672350 posted

    Sounds Good

    Well Done Uzair Tahir , I appreciate your work

    it helped me alot

     

    Regards,

    Ghazanffer Javaid

    Tuesday, August 12, 2008 2:11 AM
  • User2142095193 posted

    I am having the same problem as Agapito.  I am running Vista Business / IIS 7.

    I've followed the instructions here:

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

    I don't think this article applies to vista / IIS7. I'm still stuck.

    Please help.

     

    Thanks,

     

    Sam 

    Friday, August 22, 2008 11:57 PM