Excel을 DataTable로 변환

1941 단어 Datatable
public static DataTable ExcelToDataTable(string strExcelFileName, string strSheetName)



{     



string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + strExcelFileName + ";" +"Extended Properties=Excel 5.0;";     



string strExcel = string.Format("select * from [{0}$]", strSheetName);  



    DataSet ds = new DataSet();     



using (OleDbConnection conn = new OleDbConnection(strConn))   



  {         



conn.Open(); 



        OleDbDataAdapter adapter = new OleDbDataAdapter(strExcel, strConn);     



    adapter.Fill(ds, strSheetName);   



      conn.Close();     



}     



return ds.Tables[strSheetName];}

좋은 웹페이지 즐겨찾기