Click here to Skip to main content
15,895,813 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
How to resove the Issue of data exporting to an excel sheet when deployed in IIS?
I am using asp.net with c#. I want to populate data from datatable to an existing excel template. Its working fine iin local server but not in IIS. I am getting the following error:
System.UnauthorizedAccessException: 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)).
Posted

1 solution

I use the ACE engine with OleDb to write to Excel: Simplified Database Access via ADO.NET Interfaces[^]

I avoid interop.
 
Share this answer
 
Comments
Kandiya 2-Jan-15 4:06am    
I want to use Interop dll itself. My code is as follows:
Microsoft.Office.Interop.Excel.Application xla = new Microsoft.Office.Interop.Excel.Application();
Excel.Workbook vb = (Excel.Workbook)(xla.Workbooks._Open(ExcelFilePath, 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)); // open the existing excel file

int numberOfWorkbooks = xla.Workbooks.Count; // get number of workbooks (optional)

Excel.Worksheet ws = (Excel.Worksheet)xla.Worksheets[1];


xla.Visible = true;


for (int i = 0; i < dt.Rows.Count; i++)
{
ws.Cells[ExcelRowCnt, 1] = dt.Rows[i]["SRNo"].ToString();
ws.Cells[ExcelRowCnt, 2] = dt.Rows[i]["CSDReceivedDate"].ToString();
ws.Cells[ExcelRowCnt, 3] = dt.Rows[i]["UNBBankName"].ToString();
ws.Cells[ExcelRowCnt, 4] = dt.Rows[i]["CustomerName"].ToString();
ws.Cells[ExcelRowCnt, 5] = dt.Rows[i]["Gender"].ToString();
ws.Cells[ExcelRowCnt, 6] = dt.Rows[i]["PolicyNo"].ToString();
ws.Cells[ExcelRowCnt, 7] = dt.Rows[i]["PlanName"].ToString();
ws.Cells[ExcelRowCnt, 8] = dt.Rows[i]["SumAssured"].ToString();
ws.Cells[ExcelRowCnt, 9] = dt.Rows[i]["PolicyTerm"].ToString();
ws.Cells[ExcelRowCnt, 10] = dt.Rows[i]["Currency"].ToString();
ws.Cells[ExcelRowCnt, 11] = dt.Rows[i]["AnnualPremium"].ToString();
ws.Cells[ExcelRowCnt, 12] = dt.Rows[i]["NextPremiumThrough"].ToString();
ws.Cells[ExcelRowCnt, 13] = dt.Rows[i]["CustomerDocuments"].ToString();
ws.Cells[ExcelRowCnt, 14] = dt.Rows[i]["SubmissionDate"].ToString();
ws.Cells[ExcelRowCnt, 15] = dt.Rows[i]["Actions"].ToString();
ws.Cells[ExcelRowCnt, 16] = dt.Rows[i]["Remarks"].ToString();
ws.Cells[ExcelRowCnt, 17] = dt.Rows[i]["Date"].ToString();

ExcelRowCnt = ExcelRowCnt + 1;

}

// CLEAR the Excel Application Objects

//xla.Workbooks.Close();
xla.Quit();
xla = null;
ws = null;
PIEBALDconsult 2-Jan-15 9:52am    
Interop sucks; don't use it.

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