using (OpenFileDialog file = new OpenFileDialog()) { file.Title = "请选择文件"; file.Filter = "文件|*.xls"; if(file.ShowDialog()== System.Windows.Forms.DialogResult.OK){ string connStr = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + file.FileName + ";" + "Extended Properties='Excel 8.0';"; using (OleDbConnection conn = new OleDbConnection(connStr)) { conn.Open(); string sql = "select * from [person$]"; using (OleDbDataAdapter adapter = new OleDbDataAdapter(sql, conn)) { DataSet ds = new DataSet(); adapter.Fill(ds, "person"); System.Data.DataTable tables = ds.Tables["person"]; foreach (DataRow rows in tables.Rows) { person.Insert(new Person() { PID=Convert.ToInt16(rows[0]), PName = rows[1].ToString(), PSex = rows[3].ToString(), PAge = Convert.ToInt16(rows[2]), PJob = rows[4].ToString() }); } this.DataBind(); }} } }