c#如何实现excel的表间传值(把一excel表内容复制到另一excel表)?

来源:互联网 发布:椭圆宏程序编程实例 编辑:程序博客网 时间:2024/05/16 17:51

从Excel读取第一个sheet的数据到dataset中 ,将dataset中的数据写入第二个sheet
 

 

#region  Excel----Access
            #region  GetDataFromExcel
            //string strCon = @" Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = E:/Documents and Settings/Administrator/桌面/Completeness_Xueyp_20090212.xls;Extended Properties=Excel 8.0";
            //OleDbConnection myConn = new OleDbConnection(strCon);
            //string strCom = " SELECT * FROM [Sheet3$] ";
            //myConn.Open();
            //OleDbDataAdapter myCommand = new OleDbDataAdapter(strCom, myConn);
            //DataSet myDataSet = new DataSet();
            //myCommand.Fill(myDataSet, "[Sheet3$]");
            //myConn.Close();
            #endregion

            #region Access----Excel

            string sql = @"insert into TBL_ShortCutAccount select * from[Excel 8.0;
                        database=E:/Documents and Settings/Administrator/桌面/Completeness_Xueyp_20090212.xls].[Sheet2$]";

            string strCon = @" Provider = Microsoft.Jet.OLEDB.4.0 ;
                            Data Source = E:/Documents and Settings/Administrator/桌面/AllDb/一般服务业/一般服务业.ekj;";

            OleDbConnection myConn = new OleDbConnection(strCon);
            myConn.Open();
            OleDbCommand comm = new OleDbCommand(sql, myConn);
            int val = comm.ExecuteNonQuery();
            if (val > 0)
            {
                MessageBox.Show("数据导入成功!", "数据导入", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            myConn.Close();

            #endregion

这个是Access的。其他的数据库一样,不过MS-SQL好像比这个还简单点。。网上这个很多

原创粉丝点击