// string conString = @"Data Source =.; Initial Catalog = XXXX; User Id = XXXX; Password = XXXX;"; SqlConnection sqlCon = new SqlConnection(conString); sqlCon.Open(); SqlDataAdapter da = new SqlDataAdapter("select RollNo,Color_Name,Cand_Name,BatchNo from Batch_View where BatchNo='" + BatchNo + "'", sqlCon); System.Data.DataTable dtMainSQLData = new System.Data.DataTable(); da.Fill(dtMainSQLData); DataColumnCollection dcCollection = dtMainSQLData.Columns; Export Data into EXCEL Sheet Microsoft.Office.Interop.Excel.ApplicationClass ExcelApp = new Microsoft.Office.Interop.Excel.ApplicationClass(); // this is where the problem is ExcelApp.Application.Workbooks.Add(Type.Missing); // ExcelApp.Cells.CopyFromRecordset(objRS); for (int i = 1; i < dtMainSQLData.Rows.Count + 1; i++) { for (int j = 1; j < dtMainSQLData.Columns.Count + 1; j++) { if (i == 1) { ExcelApp.Cells[i, j] = dcCollection[j - 1].ToString(); } else { ExcelApp.Cells[i, j] = dtMainSQLData.Rows[i - 1][j - 1].ToString(); } } } ExcelApp.ActiveWorkbook.SaveCopyAs("C:\\Documents and Settings\\All Users\\Desktop\\test.xls"); ExcelApp.ActiveWorkbook.Saved = true; ExcelApp.Quit(); MessageBox.Show("Data Exported Successfully into Excel File");
Error Message is Error 86 Cannot embed interop type 'Microsoft.Office.Interop.Excel.AppEvents_Event' found in both assembly 'c:\WINDOWS\assembly\GAC\Microsoft.Office.Interop.Excel\11.0.0.0__71e9bce111e9429c\Microsoft.Office.Interop.Excel.dll' and 'c:\Program Files\Microsoft Visual Studio 10.0\Visual Studio Tools for Office\PIA\Office12\Microsoft.Office.Interop.Excel.dll'. Consider setting the 'Embed Interop Types' property to false. PET
Quote:Consider setting the 'Embed Interop Types' property to false.
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)