2
When the system runs on the server this error occurs: 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)).
There are other systems on the same server that do not give error, this is the error generated:
On my machine works perfectly, this is the code that generates the excel file:
protected void TESTE_GerarExcel()
{
#region :: GERAR ARQUIVO EXCEL ::
var excelApp = new Excel.Application();
excelApp.Workbooks.Add();
Excel._Worksheet workSheet = (Excel.Worksheet)excelApp.ActiveSheet;
workSheet.Cells[1, "A"] = "NOME CLIENTE";
workSheet.Cells[1, "B"] = "DESCRIÇÃO";
workSheet.Cells[1, "C"] = "QTDE PARCELA";
workSheet.Cells[1, "D"] = "VALOR PARCELA";
workSheet.Cells[1, "E"] = "DATA VENCIMENTO";
workSheet.Cells[1, "F"] = "SITUAÇÃO";
workSheet.Cells[1, "G"] = "BOLETO ENVIADO";
var row = 1;
row++;
workSheet.Cells[row, "A"] = "IND. FARMACÊUTICA";
workSheet.Cells[row, "B"] = "ALUGUE DE SALA";
workSheet.Cells[row, "C"] = "2";
workSheet.Cells[row, "D"] = "200,10";
workSheet.Cells[row, "E"] = "30/05/2016";
workSheet.Cells[row, "F"] = "PENDENTE";
workSheet.Cells[row, "G"] = "NÃO ENVIADO";
workSheet.Columns[1].AutoFit();
workSheet.Columns[2].AutoFit();
workSheet.Columns[3].AutoFit();
workSheet.Columns[4].AutoFit();
workSheet.Columns[5].AutoFit();
workSheet.Columns[6].AutoFit();
workSheet.Columns[7].AutoFit();
workSheet.Range["A1", "G1"].AutoFormat(Excel.XlRangeAutoFormat.xlRangeAutoFormatSimple);
excelApp.Columns.AutoFit();
string nome = "Contas_a_Receber_" + System.DateTime.Now.ToString().Replace(" ", "_").Replace("/", "_").Replace(":", "_");
var path = Path.Combine(Server.MapPath("~/Content/Uploads"), nome);
excelApp.ActiveWorkbook.SaveCopyAs(path + ".xlsx");
#endregion
}

That component
Excelisn’t something native to Asp.net, is it? Maybe you missed installing/configuring something on the server (which you did on your machine). Although the error message indicates "access denied". You are using a similar execution environment (same folders and same users and/or rights) in both tests?– Luiz Vieira
It seems to me that the server does not have Excel installed, I’m waiting for a response from the support with this confirmation, the way that to want to generate the file is necessary to install Excel that uses the dll
Microsoft.Office.Interop.Excel.dll, need to somehow generate excel and save on user’s machine.– hard123
Ah, ok. If that’s right, create an answer yourself by explaining these details. : ) Good luck! P.S.: Depending on the content you produce, an alternative that may be feasible is for you to generate one CSV (essentially a text file) and send to the user to download and open locally. Excel is able to open such files.
– Luiz Vieira