发布网友 发布时间:2022-04-08 04:18
共2个回答
懂视网 时间:2022-04-08 08:39
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表
标签:
热心网友 时间:2022-04-08 05:47
int i =0;