1.直接读取Excel数据到DataReader
public OleDbDataReader GetReader(string filePath)
{
try
{
string strConn = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties='Excel 8.0;HDR=NO;IMEX=1'", filePath);
OleDbConnection con = new OleDbConnection(strConn);
con.Open();
OleDbCommand cmd = con.CreateCommand();
cmd.CommandText = " select * from [Sheet1$]";
OleDbDataReader odr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
return odr;
}
catch (Exception ex)
{
ShowInfo(Color.Red, "导入失败,"+ex.Message);
return null;
}
}