转自[http://blog.csdn.net/bodybo/article/details/43191319]
程序需要读取Exel文件,有如下代码段
[csharp] view plaincopy
- object oMissing = System.Reflection.Missing.Value;
- Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application();
- excelApp.UserControl = true;
- excelApp.DisplayAlerts = false;
- excelApp.Application.Workbooks.Open(strFilePath, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing);
- Workbook workBook = excelApp.Workbooks[1];
- Worksheet workSheet = (Worksheet)workBook.Worksheets[1];
下面这句话之前的.net2.0上没问题,在.net4.0上报错 error CS1969: 找不到编译动态表达式所需的一个或多个类型。是否缺少引用?
[csharp] view plaincopy
- Worksheet workSheet = (Worksheet)workBook.Worksheets[1];
解决方案:修改引用(Microsoft.Office.Interop.Excel)的属性“嵌入互操作类型”由True改为False即可
时间: 2024-10-10 05:53:39