读取Excel


// 产生连接字符串
string connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=student.xls;"
+ "Extended Properties='Excel 8.0;HDR=YES;IMEX=1'";

// 定义SQL
string sql = "SELECT * FROM [Sheet1$]";

DataTable dt = new DataTable();

using (OleDbConnection conn = new OleDbConnection(connString))
{
OleDbDataAdapter adapter = new OleDbDataAdapter(sql, conn);
adapter.Fill(dt);
}

dataGridView1.DataSource = dt;

posted @ 2014-06-27 21:32  花开见我  阅读(159)  评论(0编辑  收藏  举报