Click here to Skip to main content
15,941,828 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My Error:
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)).


My Code:

if (FileExtension == ".xls")
{

string NewFileLocation = string.Empty;
NewFileLocation = string.Format("{0}{1}", FileLocation, "x");

if (System.IO.File.Exists(NewFileLocation))
System.IO.File.Delete(NewFileLocation);

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

Microsoft.Office.Interop.Excel.Workbook eWorkbook = excelApp.Workbooks.Open(FileLocation, 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);

eWorkbook.SaveAs(NewFileLocation, Microsoft.Office.Interop.Excel.XlFileFormat.xlOpenXMLWorkbook, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);

eWorkbook.Close(false, Type.Missing, Type.Missing);

FileLocation = NewFileLocation;
FileExtension = ".xlsx";
}
Posted
Updated 22-Apr-15 1:19am
v2
Comments
Richard Deeming 22-Apr-15 7:46am    
Using Office interop in an ASP.NET application is not supported:
https://support.microsoft.com/en-us/kb/257757[^]
"Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment."

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900