码迷,mamicode.com
首页 > 数据库 > 详细

使用oledb读取excel表

时间:2015-07-24 20:16:05      阅读:122      评论:0      收藏:0      [点我收藏+]

标签:

string path = "C:\\Users\\aaa\\Desktop\\aa.xls";
            string conn = "Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source =" + path + ";Extended Properties=‘Excel 8.0;HDR=False;IMEX=1‘";

            OleDbConnection oleCon = new OleDbConnection(conn);

            oleCon.Open();

            string Sql = "select * from [Sheet1$]";

            OleDbDataAdapter mycommand = new OleDbDataAdapter(Sql, oleCon);

            DataSet ds = new DataSet();

            mycommand.Fill(ds, "[Sheet1$]");

            oleCon.Close();

            int count = ds.Tables["[Sheet1$]"].Rows.Count;

            MessageBox.Show(count+"");

            for (int i = 0; i < count; i++)
            {

                string tUserID, tUserName, tDept, tEmail, tLeader, tAngent;

                tUserID = ds.Tables["[Sheet1$]"].Rows[i][0].ToString().Trim();

                tUserName = ds.Tables["[Sheet1$]"].Rows[i][1].ToString().Trim();
                tDept = ds.Tables["[Sheet1$]"].Rows[i][2].ToString().Trim();

                MessageBox.Show(tUserID + "," + tUserName + "," + tDept);


            }

 

使用oledb读取excel表

标签:

原文地址:http://www.cnblogs.com/lunawzh/p/4674240.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!