首页 > 代码库 > 把excel读入DataTable

把excel读入DataTable

 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