//exclPath:文件路径
private void DataFromExcl(string exclPath)
{
string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + exclPath + ";" + "Extended Properties=Excel 8.0;"; 可选参数HDR=NO;IMEX=1。HDR=YES 有两个值:YES/NO,表示第一行是否字段名,默认是YES,第一行是字段名,IMEX=1 解决数字与字符混合时,识别不正常的情况.
OleDbConnection conn = new OleDbConnection(strConn);
conn.Open();
string strExcel = "";
OleDbDataAdapter myCommand = null;
DataSet ds = null;
strExcel = "select * from [Sheets
Name$]";//;SheetsName是Excl页签名称
myCommand = new OleDbDataAdapter(strExcel, strConn);
ds = new DataSet();
myCommand.Fill(ds, "table1");
for (int i = 0; i < ((ds.Tables)[0].Rows).Count; i++)
{
object[] a = (ds.Tables)[0].Rows[i].ItemArray;
}
}