oledb快速导入Excel案例

时间:2021-05-19 23:32:19

DataTable dtImportExcel = null;
string pathFile = Server.MapPath("~/ErrorCatory.xlsx");
//string strConn = @"Provider=Microsoft.Ace.OleDb.12.0;" + "data source=" + UploadFilePath + ";Extended Properties='Excel 12.0; HDR=Yes; IMEX=1;'";
//strConn = string.Format(strConn, UploadFilePath);
//OleDbConnection connExcel = new OleDbConnection(strConn);
//// where [紧急程度] is not null
//string commandText = string.Format("SELECT * FROM [2013.01$] where [紧急程度] is not null ");
//try
//{
// dtImportExcel = new DataTable("ImportCheck");
// OleDbDataAdapter daImportExcel = new OleDbDataAdapter(commandText, connExcel);
// daImportExcel.Fill(dtImportExcel);
//}
//catch (Exception ex)
//{

//}
//finally
//{

//}