本文介绍了如何处理这个错误!!!!!!!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 // string conString = @ 数据源=。;初始目录= XXXX;用户ID = XXXX;密码= XXXX;; SqlConnection sqlCon = new SqlConnection(conString); sqlCon.Open(); SqlDataAdapter da = new SqlDataAdapter( select来自Batch_View的RollNo,Color_Name,Cand_Name,BatchNo,其中BatchNo =' + BatchNo + ',sqlCon); System.Data.DataTable dtMainSQLData = new System.Data.DataTable(); da.Fill(dtMainSQLData); DataColumnCollection dcCollection = dtMainSQLData.Columns; 导出数据进入 EXCEL表 Microsoft.Office.Interop.Excel.ApplicationClass ExcelApp = new Microsoft.Office.Interop.Excel.ApplicationClass(); // 这就是问题所在 ExcelApp.Application.Workbooks.Add(Type。失踪); // 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( 数据成功导入Excel文件); 得到此错误.. 错误消息是错误86无法嵌入互操作类型'Microsoft .Office.Interop.Excel.AppEvents_Event'在程序集'c:\ WINDOWS \assembly \ GAC \ Microsoft.Office.Interop.Excel \11.0.0.0__71e9bce111e9429c\Microsoft.Office.Interop.Excel中找到。 dll'和'c:\Program Files\Microsoft Visual Studio 10.0 \Visual Studio Tools for Office \ PIA \Office12 \ Mysrosoft.Office.Interop.Excel.dll'。考虑将嵌入互操作类型属性设置为false。 PET 解决方案 上面的错误也给出了解决方案。 Quote:考虑将'Embed Interop Types'属性设置为false。 所以只需在Visual Studio 2010/12/13中打开程序集的Properties选项卡,然后将Embed Interop Types设置为False。 如果您需要更多信息,请查看此链接:无法嵌入Interop类型 // 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");And got this error..Error Message is Error86Cannot 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 解决方案 On above error it's giving the solution also.Quote:Consider setting the 'Embed Interop Types' property to false.So Just open the Properties tab for the assembly in Visual Studio 2010/12/13 and set "Embed Interop Types" to "False".Please check this link if you need more info : Interop type cannot be embedded 这篇关于如何处理这个错误!!!!!!!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-09 03:58