例如,读取第4行第5列的数据!网上好多例子都说不清楚

解决方案 »

  1.   


    excelApplication = new Excel.ApplicationClass();
                excelWorkBooks = excelApplication.Workbooks;
                excelWorkBook = ((Excel.Workbook)excelWorkBooks.Open(path,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value));           
                excelApplication.Visible = false;
    excelWorkSheet = (Excel.Worksheet)excelWorkBook.Worksheets[1];string s=((Excel.Range)excelWorkSheet.Cells[4, 5]).Text.ToString()
      

  2.   

    这个是用sql实现的。数据放到了datatable里了
    #  string strConnection = "Provider=Microsoft.ACE.OLEDB.12.0;";  
    #             strConnection += @"Data Source=C:\Documents and Settings\v-changl\My Documents\couse.xlsx;";  
    #             strConnection += "Extended Properties=\"Excel 12.0 Xml;HDR=YES\";";  
    #             OleDbConnection objConnection = new OleDbConnection(strConnection);  
    #             objConnection.Open();  
    #             OleDbDataAdapter myCommandd = new OleDbDataAdapter("select * from [Sheet1$]", objConnection);  
    #             DataSet ds = new DataSet();  
    #             myCommandd.Fill(ds, "[Sheet1$]");  
    #             System.Data.DataTable dt = ds.Tables["[Sheet1$]"];  
      

  3.   

    第4行第5列的数据!
    dt.Rows[4][5].ToString()
    或者
    ds.Tables[0].Rows[4][5].ToString()
      

  4.   

    Excel.Application myExcel;
    public string  ReadData(int row, int column)
            {
                Excel.Range range = myExcel.get_Range(myExcel.Cells[row, column], myExcel.Cells[row, column]);
                return range.Text.ToString();
            }
      

  5.   

    或读取excel到数据集如dataset,判断dataset行数,获取数据
    ds.Tables[0].Rows[3][4].ToString()