//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;
}
}