代码改变世界

c# OLEDB 读取excel

2010-03-10 18:05  zhangbaoyu  阅读(289)  评论(0编辑  收藏  举报

string connStr = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source ='" + Server.MapPath(filename) + "';Extended Properties='Excel 8.0;HDR=No;IMEX=1'";
OleDbConnection conn = new OleDbConnection(connStr);
conn.Open();
OleDbDataAdapter myDa = new OleDbDataAdapter("select * from [Sheet1$]", conn);
DataSet ds = new DataSet();
myDa.Fill(ds, "xls");
conn.Close();