需要用到什么命名空间,如何读取单元格数据,能不能具体的说说看

解决方案 »

  1.   

    你需要在 References 点击右键 选择 Add References 在选择COM 选项卡,查找 MicroSoft Office 11.0 Object Library 添加这个组件,就可以开发了。
      

  2.   

    有一个类似的例子,经过测试可以使用,已经用在了一个小项目上!http://download.csdn.net/source/2565456
      

  3.   

    public DataSet readExcelData(string sFile)
     {
      DataSet result = null;
      string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + sFile + ";" + "Extended Properties=Excel 8.0;";
      OleDbConnection conn = new OleDbConnection(strConn);
      try
      {
              conn.Open();
              string strExcel = "select * from [sheet1$]";
              OleDbDataAdapter myCommand = new OleDbDataAdapter(strExcel, strConn);
              result = new DataSet();
              myCommand.Fill(ds, "table1");
      }
      finally
      {
       conn.Close();
      }
      return result;
     }
      

  4.   

    string   fileName; fileName   =   Server.MapPath( ". ")+ "\\excel\\ajcl.xls "; object   o   =   System.Reflection.Missing.Value; 
    Excel.Application   oXL   =   new   Excel.ApplicationClass(); 
    //Response.Write( " <script> alert( "+fileName+ ") </script> "); 
    Excel.Workbook   oWB   =   oXL.Workbooks.Open(fileName,o,o,o,o,o,o,o,o,o,o,o,o); 
    Excel.Worksheet   oSheet   =   (Excel.Worksheet)oWB.Worksheets[1]; 
    oXL.Visible   =   true; string   strSql   =   Session[ "sql "].ToString().Trim(); 
    SqlDataAdapter   MyCommand   =   new   SqlDataAdapter(strSql,MyConn); 
    DataSet   ds   =   new   DataSet(); 
    MyCommand.Fill(ds); 
    DataTable   MyTable   =   new   DataTable(); 
    MyTable   =   ds.Tables[0]; 
    if(MyTable.Rows.Count   !=   0) 

    for   (int   i   =   0;i <MyTable.Rows.Count;i++) 

    DataRow   MyRow   =   MyTable.Rows[i]; 
    string   str_xh   =   MyRow[ "xh "].ToString().Trim(); 
    oSheet.Cells[i+4,1]   =   MyRow[ "ajbh "].ToString().Trim(); 
    oSheet.Cells[i+4,2]   =   MyRow[ "csmc "].ToString().Trim(); 
    oSheet.Cells[i+4,3]   =   MyRow[ "lb "].ToString().Trim(); 
    string   str_ajly           =   MyRow[ "jclx "].ToString().Trim();
      

  5.   

      由于我的excel中,还有其他的图形啊什么的,不是规则的表,所以可能用dataset是不是不太适合?
                  Object refmissing = System.Reflection.Missing.Value;
                Excel._Application exc = new Excel.ApplicationClass();
                exc.Visible = true;
                Excel.Workbooks workbooks = exc.Workbooks;
                workbooks._Open("E:\\edwardliu\\Timereport status Query Robot.xlsm", refmissing, refmissing, refmissing, refmissing, refmissing, refmissing, refmissing, refmissing, refmissing, refmissing, refmissing, refmissing);            Excel.Worksheet sheet = (Excel.Worksheet)exc.Worksheets.get_Item(1);
                return sheet.Cells[3,12].ToString();以上是我写的读取单元格的代码,但是其中读出来是System.__ComObject,请问是什么原因呢?