locked
Export to Excel not working in server RRS feed

  • Question

  • User-1997017258 posted

    Hi all

    i am new in this forum.and really happy to join this.

    i am doing export to excel operation using below code.

    public void ExcelExport(System.Data.DataTable tblExportData, string TempFilePath,string userInfo,bool headerStatus)

    {

    try

    {

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

    excelApp.Workbooks.Open(TempFilePath, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);

     

    //Writing Header in Excel

    if (headerStatus == true)

    {

    for (int i = 0; i < tblExportData.Columns.Count; i++)

    {

    excelApp.Cells[7, i + 1] = tblExportData.Columns[i].ColumnName;

    }

    }

    //Writing Data in Excel

    for (int i = 1; i <= tblExportData.Rows.Count; i++)

    {

    for (int j = 0; j < tblExportData.Columns.Count; j++)

    {

    string colName = tblExportData.Columns[j].ColumnName;

    excelApp.Cells[i + 7, j+1] = tblExportData.Rows[i-1][colName];

    }

    }

    //Create a worksheet object

    Microsoft.Office.Interop.Excel.Sheets sheets = excelApp.Worksheets;

    //from the collection of worksheet select one worksheet

    Microsoft.Office.Interop.Excel.Worksheet mySheet = (Microsoft.Office.Interop.Excel.Worksheet)sheets.get_Item(1);

    //select the cell in the worksheet

    Microsoft.Office.Interop.Excel.Range myCell1 = (Microsoft.Office.Interop.Excel.Range)mySheet.get_Range("A6", "A6");

    myCell1.Value2 = userInfo;

    myCell1.Font.Color = System.Drawing.Color.Black.ToArgb();

    excelApp.Visible = true;

     

    }

    catch (Exception ex)

    {

    }

    }

     

    it's working fine. but when i deployed this on relience server then it stops to work. i mean exporting to excel not working. Even it's not generating any error also. can any one help me please.

    thanks to you all in advance.

    Binod

    Monday, June 15, 2009 10:25 AM

All replies

  • User-1952482173 posted

    One possibility is the permission to write Excel file to thr folder. You should grant the folder to be accessed by ASP.NET user.

    Also, change your code to see the possible error:

    catch (Exception ex)

    {

           throw ex; 

    }

    Monday, June 15, 2009 11:27 AM
  • User-1997017258 posted

    Hi che3358

    Thanx a lot for quick reply

    i am satiesfied with your answer, there is the possibility of some security access. But could you please tell me that how i will eanble permission to write excel file.

     

     

    Wednesday, June 17, 2009 2:39 AM
  • User-1952482173 posted

    What error message did you get?

    Wednesday, June 17, 2009 9:01 AM
  • User-1997017258 posted

    Hi che3358

    I am not getting any error......

    Friday, June 19, 2009 1:20 AM
  • User-1997017258 posted

    Hi che3358

    i am really sorry for my previous reply...

    Actually i am getting this error: "Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80070005."

    and also i tried this setting, given in this link: http://blog.crowe.co.nz/archive/2006/03/02/589.aspx

    but still it is not working.........

    Friday, June 19, 2009 6:50 AM
  • User-1997017258 posted

    Hi All

    Actually i am getting this error: "Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80070005." when i run this application on server. In local machine it's working fine...

    and also i tried this setting, given in this link: http://blog.crowe.co.nz/archive/2006/03/02/589.aspx

    but still it is not working.........

    can anyone please help me...

    Friday, June 19, 2009 6:52 AM
  • User-1952482173 posted

    Probably your server setups a GROUP for user. Instead of granting to ASPNET account, you can try to grant the group. For example, my company uses group SysDeveloper, so, we just grant this account instead of ASPNET. Ask your system administrator for this server.

    Friday, June 19, 2009 9:14 AM