Buen dia, Tengo un problema: Estoy haciendo una aplicacion web con MVC, C#, JS.. En esta app creo un archivo XLSX con la libreria de interop, todo estaba perfecto hasta que puse la app en el servidor de despliege, me marca un error:
System.Runtime.InteropServices.COMException: Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).
Al parecer el detalle es porque no tengo el Interop/office instalado en el servidor, ya que yo no tengo permisos para instalar en ese servidor, habría alguna manera de importar la librería en el proyecto o crear el excel desde otro método?
agrego el codigo..
public void ExportToExcel(List<Model> EXAMPLE)
{
Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application();
excel.Workbooks.Add();
Microsoft.Office.Interop.Excel._Worksheet workSheet = excel.ActiveSheet;
try
{
workSheet.Cells[1, "A"] = "Nombre";
workSheet.Cells[1, "B"] = "Apellido";
int row = 2; // start row (in row 1 are header cells)
foreach (Model ex in EXAMPLE)
{
workSheet.Cells[row, "A"] = ex.nombre;
workSheet.Cells[row, "B"] = ex.apellido;
row++;
}
workSheet.Range["A1"].AutoFormat(Microsoft.Office.Interop.Excel.XlRangeAutoFormat.xlRangeAutoFormatClassic1);
string fileName = "ExcelData.xlsx";
path = Server.MapPath("~/Uploads");
path = Path.Combine(path, fileName);
if (System.IO.File.Exists(path)){
System.IO.File.Delete(path);
}
workSheet.SaveAs(path);
}
catch (Exception exception)
{
exception.Message,
}
finally
{
excel.Quit();
if (excel != null)
System.Runtime.InteropServices.Marshal.ReleaseComObject(excel);
if (workSheet != null)
System.Runtime.InteropServices.Marshal.ReleaseComObject(workSheet);
excel = null;
workSheet = null;
GC.Collect();
}
}