publicDataSetImportExcel(stringstrFileName)//strFileName指定的路徑+檔名.xls{if(strFileName!=""){stringconn="Provider=Microsoft.Jet.OLEDB.4.0;DataSource="+strFileName+";ExtendedProperties=Excel8.0";stringsql="select*from[Sheet1$]";OleDbDataAdapterda=newOleDbDataAdapter(sql,conn);DataSetds=newDataSet();try{da.Fill(ds,"datatable");}catch{}returnds;}else{returnnull;}}這個方法我經常用,轉成dataset和datatable沒什麼太大區別吧,反正ds.Tables[0]就是dataTable了
publicDataSetImportExcel(stringstrFileName)//strFileName指定的路徑+檔名.xls{if(strFileName!=""){stringconn="Provider=Microsoft.Jet.OLEDB.4.0;DataSource="+strFileName+";ExtendedProperties=Excel8.0";stringsql="select*from[Sheet1$]";OleDbDataAdapterda=newOleDbDataAdapter(sql,conn);DataSetds=newDataSet();try{da.Fill(ds,"datatable");}catch{}returnds;}else{returnnull;}}這個方法我經常用,轉成dataset和datatable沒什麼太大區別吧,反正ds.Tables[0]就是dataTable了