先去google如何操作excel,读取单元格内容,入库

解决方案 »

  1.   

    我还是个新手   主要是excel这方面的导入导出基本没用过   所以不会啊
      

  2.   


    调用: EcxelToDataGridView("test.xls",dataGridView1);
      /// Excel数据导入方法
            public void EcxelToDataGridView(string filePath,DataGridView dgv)
            {
                //根据路径打开一个Excel文件并将数据填充到DataSet中
                string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = " + filePath + ";Extended Properties ='Excel 8.0;HDR=NO;IMEX=1'";//HDR=YES 有两个值:YES/NO,表示第一行是否字段名,默认是YES,第一行是字段名
                OleDbConnection conn = new OleDbConnection(strConn);
                conn.Open();
                string strExcel = "";
                OleDbDataAdapter myCommand = null;
                DataSet ds = null;
                strExcel = "select  * from   [sheet1$]";
                myCommand = new OleDbDataAdapter(strExcel, strConn);
                ds = new DataSet();
                myCommand.Fill(ds, "table1");
                dataGridView1.DataSource = ds.Tables[0].DefaultView; 
    }
      

  3.   

    http://www.cnblogs.com/yxhblog/archive/2012/06/06/2537642.html
      

  4.   

    大神   能给个全一点的代码么   [sheet1$]这个表名怎么获取啊
      

  5.   

    就是你建立EXCEL的sheet1,默认是这个,如果你用别的,这里修改就可,你还有什么疑问?
         private void button1_Click(object sender, EventArgs e)
            {
                 //调用
                EcxelToDataGridView(@"d:\\test.xls", dataGridView1);
         }
      

  6.   

    可以的,  EcxelToDataGridView(你文件名的参数, dataGridView1);