当前位置:Gxlcms > 数据库问题 > 使用oledb读取excel表

使用oledb读取excel表

时间:2021-07-01 10:21:17 帮助过:2人阅读

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表

标签:

人气教程排行