DataSet ds = new DataSet();
//获取全部数据
string strConn = "Provider=Microsoft.Ace.OleDb.12.0;" + "Data Source=" + 文件路径+ ";" + "Extended Properties='Excel 12.0;HDR=yes;IMEX=1'";
OleDbConnection conn = new OleDbConnection(strConn);
try
{
conn.Open();
string strExcel = "";
OleDbDataAdapter myCommand = null;
DataTable dt = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
string sheetName = dt.Rows[0]["TABLE_NAME"].ToString().Trim();//sheet默认排序
strExcel = string.Format("select * from [{0}]", sheetName);
myCommand = new OleDbDataAdapter(strExcel, strConn);
myCommand.Fill(ds);
}
注意:dt.Rows[0]["TABLE_NAME"].ToString().Trim();取出的sheet名称是默认排序后的第一个。