码迷,mamicode.com
首页 > 其他好文 > 详细

把excel读入DataTable

时间:2014-12-28 16:47:34      阅读:207      评论:0      收藏:0      [点我收藏+]

标签:

 1  private DataTable GetExcelTable(DataRow  row)
 2         {
 3            
 4             string path = ConfigurationManager.AppSettings["UploadPath"].ToString();
 5             path = System.IO.Path.Combine(path, row["BB_FILE_PATH"].ToString().Replace("../", ""));
 6             string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + path + ";" + "Extended Properties=Excel 8.0;";
 7             OleDbConnection conn = new OleDbConnection(strConn);
 8             conn.Open();
 9             OleDbDataAdapter adp = new OleDbDataAdapter("Select * from [Sheet1$A1:AB1000] WHERE number is not null ", conn);
10             DataSet ds = new DataSet();
11             adp.Fill(ds, "Book1");
12             if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
13                 return ds.Tables[0];
14             return null;
15         }

 

把excel读入DataTable

标签:

原文地址:http://www.cnblogs.com/sunxi/p/4190090.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!