public static DataTable et_excel()
{
DataTable dt = new DataTable();
OleDbConnection excelConnection = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;"
+ @"Data Source=F:\excel_filename.xls;"
+ @"Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1;""");
excelConnection.Open();
try
{
OleDbDataAdapter dbAdapter = new OleDbDataAdapter("SELECT * FROM [Sheet1$]", excelConnection);
dbAdapter.Fill(dt);
}
finally
{
excelConnection.Close();
}
return dt;
}
{
DataTable dt = new DataTable();
OleDbConnection excelConnection = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;"
+ @"Data Source=F:\excel_filename.xls;"
+ @"Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1;""");
excelConnection.Open();
try
{
OleDbDataAdapter dbAdapter = new OleDbDataAdapter("SELECT * FROM [Sheet1$]", excelConnection);
dbAdapter.Fill(dt);
}
finally
{
excelConnection.Close();
}
return dt;
}
No comments:
Post a Comment