标签:style blog color os io 文件 cti div
protected static DataTable GetDataTable(string fileName) { //execl 2003和2007以上的版本所用的引擎是不一样的 //excel2007,兼容2003 //string strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileName + " ;Extended Properties=Excel 8.0";//2003 //string strCon = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + fileName + ";Extended Properties=‘Excel 12.0 Xml;HDR=YES;IMEX=1‘;";//2007以上 string strCon = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + fileName + ";Extended Properties=‘Excel 12.0 Xml;HDR=YES;IMEX=1‘;"; DataSet ds = new DataSet(); using (OleDbConnection conn = new OleDbConnection(strCon)) { string sql = "select * from [Sheet1$]"; OleDbCommand cmd = new OleDbCommand(sql, conn); OleDbDataAdapter da = new OleDbDataAdapter(cmd); da.Fill(ds); } return ds.Tables[0]; }
标签:style blog color os io 文件 cti div
原文地址:http://www.cnblogs.com/zhaolijing910/p/3924047.html