Hi i am downloding excel report it is not working when download from server but it is working on local machine here is my error and code System.Runtime.InteropServices.COMException (0x80040154): 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)). at CompanyStatics.btnexport_Click(Object sender, EventArgs e) in c:\inetpub\wwwroot\TestAdmin\CompanyStatics.aspx.cs:line 959
using ExcelAutoFormat = Microsoft.Office.Interop.Excel.XlRangeAutoFormat;
using System.Globalization;
using System.Runtime.InteropServices;
using ClosedXML.Excel;
c# Code on button click
protected void btnexport_Click(object sender, EventArgs e)
{
int companyId = Convert.ToInt32((ddlCompanyName.SelectedValue));
try
{
string path = Server.MapPath("exportedfiles\\");
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
File.Delete(path + "Company&VesselDetails.xlsx");
var xlAppToExport = new Excel.Application();
xlAppToExport.Workbooks.Add("");
Excel.Worksheet xlWorkSheetToExport = default(Excel.Worksheet);
xlWorkSheetToExport = (Excel.Worksheet)xlAppToExport.Sheets["Sheet1"];
int iRowCnt = 2;
int iRowCnt1 = 5;
// Add company Name
xlWorkSheetToExport.Cells[1, 1] = "Company Name";
// Get the range from excel.
Excel.Range rangeComp = xlAppToExport.ActiveCell.Worksheet.Cells[1, 1] as Excel.Range;
rangeComp.Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.SteelBlue);
// Set font color.
rangeComp.Font.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.White);
// Set Row Height.
rangeComp.EntireRow.RowHeight = 25.0;
// Set Column Width.
rangeComp.ColumnWidth = 40.0;
//rangeComp.HorizontalAlignment =ri;;
//end company Name
// Add Token Name
xlWorkSheetToExport.Cells[1, 2] = "Total Tokens";
// Get the range from excel.
Excel.Range rangeTokens = xlAppToExport.ActiveCell.Worksheet.Cells[1, 2] as Excel.Range;
rangeTokens.Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.SteelBlue);
// Set font color.
rangeTokens.Font.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.White);
// Set Row Height.
rangeTokens.EntireRow.RowHeight = 30.0;
// Set Column Width.
rangeTokens.ColumnWidth = 40.0;
//end Token Name
// Add Approve Token
xlWorkSheetToExport.Cells[1, 3] = "Approve Tokens";
// Get the range from excel.
Excel.Range ApproveToken = xlAppToExport.ActiveCell.Worksheet.Cells[1, 3] as Excel.Range;
ApproveToken.Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.SteelBlue);
// Set font color.
ApproveToken.Font.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.White);
// Set Row Height.
ApproveToken.EntireRow.RowHeight = 25.0;
// Set Column Width.
ApproveToken.ColumnWidth = 25.0;
//end Approve Token
// Add Remaining Tokens
xlWorkSheetToExport.Cells[1, 4] = "Remaining Tokens";
// Get the range from excel.
}
}