日期:2014-05-19  浏览次数:21068 次

C#中读取Excel文件 老是出现System._ComObject 怎么回事
读取excel单元格A1,然后在listview中显示,老是显示“System._ComObject   ”怎么回事?

代码见下,这样写对吗?

Microsoft.Office.Interop.Excel.Application   ExcelObj   =   new   Microsoft.Office.Interop.Excel.ApplicationClass();
ExcelObj.Visible   =   false;
Microsoft.Office.Interop.Excel.Workbook   theWorkbook=ExcelObj.Workbooks.Open(fileNamePath[i],Type.Missing,   Type.Missing,Type.Missing,   Type.Missing,   Type.Missing,Type.Missing,   Type.Missing,   Type.Missing,   Type.Missing,   Type.Missing,   Type.Missing,   Type.Missing,   Type.Missing,   Type.Missing);
                                                                               
                                       
Microsoft.Office.Interop.Excel.Sheets   sheets   =   theWorkbook.Worksheets;
Microsoft.Office.Interop.Excel.Worksheet   xsheet=Microsoft.Office.Interop.Excel.Worksheet)sheets.get_Item(1);
Microsoft.Office.Interop.Excel.Range   xrange   =   xsheet.get_Range( "A1 ",   Type.Missing);      

listView1.Items.Add(string.Format( "{0:f} ",   xrange[1,1]));




------解决方案--------------------
跟踪检查获取sheets、xsheet、xrange 是否为空