ASP.NET website and ms excel integration

586 views Asked by At

I am working on the asp.net website and excel integration project. I have an excel file having lots of macros that performs some calculation. I can simply pass the values of cells and based on macros formula it displays the output in other cell of excel. I need to pass those parameters from ASP.NET website and to display out put of excel on asp.net webform. I am able to implement this functionality using following code and its working fine on while development.

     Application excel = new Application();
            excel.DisplayAlerts = false;
            excel.EnableEvents = true;
            //excel.Visible = true;

            Workbook wb = excel.Workbooks.Open(path, 0, false, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", true, false, 0, true, 1, 0);
            Worksheet excelSheet = (Worksheet)wb.ActiveSheet;

            excelSheet.Cells[37, 11] = 65;
            excelSheet.Cells[37, 9] = 70;

            excelSheet.Cells[14, 8] = "A";
            excelSheet.Cells[15, 8] = "B";
            excelSheet.Cells[16, 8] = "C";


 try
            {
                excel.Run("Macro1", System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value
                    , System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value,
                    System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value,
                    System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value,
                    System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value,
                    System.Reflection.Missing.Value);
            }
            catch (Exception ex)
            { }


 try
            {
                wb.Save();
            }
            catch (Exception ex)
            { }


List<string> resultList = new List<string>();

            try
            {
                resultList.Add((excelSheet.Cells[37, 4] as Range).Value.ToString());
            }
            catch (Exception ex)
            {
                resultList.Add("");
            }
            try
            {
                resultList.Add((excelSheet.Cells[36, 9] as Range).Value.ToString());
            }
            catch (Exception ex)
            {
                resultList.Add("");
            }

When i am deploying the site to production server then i am getting following error -

Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80070005 Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)).

To resolve this issue i have applied following solution but its not working - At most of the link its mentioned to publish application with 32-bit or 64-bit, but i developed it as asp.net website so no option for 32-bit and 64-bit. At IIS i have already "Enabled 32-bit Application" to true.

0

There are 0 answers