string str = "Provider=Microsoft.Jet.OLEDB.4.0;Data source=c:\\test.xls;Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=1;\" "; //注意此连接字符串的书写
DataSet ds = new DataSet();
OleDbConnection con;
OleDbDataAdapter myadapter;
con = new OleDbConnection(str);
con.Open();
myadapter = new OleDbDataAdapter("select * from [Sheet1$]", con);
myadapter.Fill(ds, "ds");
foreach (DataRow row in ds.Tables["ds"].Rows)
{
string userInfo = row[0].ToString().Trim() + row[1].ToString().Trim() + row[2].ToString().Trim() + row[3].ToString().Trim() + row[4].ToString().Trim();
Response.Write(userInfo);
}
con.Close();