我无法在Excel中读取数据.这是我正在使用的代码:
using Excel = Microsoft.Office.Interop.Excel; Excel.Application xlApp = new Excel.Application(); Excel.Workbook xlWorkbook = xlApp.Workbooks.Open(@"Book1.xlsx",true,5,"",Excel.XlPlatform.xlWindows,"\t",false,1,0); Excel._Worksheet xlWorksheet = (Excel._Worksheet)xlWorkbook.Sheets[1]; Excel.Range xlRange = xlWorksheet.UsedRange; int rowCount = xlRange.Rows.Count; int colCount = xlRange.Columns.Count; for (int i = 1; i <= rowCount; i++) { for (int j = 1; j <= colCount; j++) { MessageBox.Show(xlWorksheet.Cells[i,j].ToString()); } }
我收到一个消息框,说出一些关于System .__ ComObject而不是一个值.
如何解决这个问题?