Cant read excel after deploying the code in server

0

i have written code to open an excel like below:

string mRangeStartCell = @"A3";
string mRangeEndCell = @"D27";
            Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application();
            Microsoft.Office.Interop.Excel.Workbooks xlWbs = xlApp.Workbooks;
            Microsoft.Office.Interop.Excel.Workbook xlWb = xlWbs.Open(ConfigurationManager.AppSettings["MasterFolderPath"] + pickupMailData.Attachment, 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);

In local it runs without any problem, but when its deployed in server it shows following error:

Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80080005 Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE)).

And in local computer i have excel 2016 version and in server excel 2010 version, And i am disposing object once all used, So can anyone can help me? Thanks in advance.

c#
excel
server
asked on Stack Overflow Nov 5, 2020 by Joseph Ganeah

1 Answer

0

You have three choices, the first one won't require you to recode anything:

  1. Install Microsoft Excel 2016 on the server (Please read this before doing so: https://support.microsoft.com/en-us/help/257757/considerations-for-server-side-automation-of-office).

  2. Use the Open XML SDK

  3. Use a 3rd party Excel library (example epplus)

I personally would choose Option 2 or 3 because it is much easier to deploy on multiple servers.

answered on Stack Overflow Nov 6, 2020 by Kevin • edited Nov 6, 2020 by Kevin

User contributions licensed under CC BY-SA 3.0