日期:2014-05-18 浏览次数:21007 次
string ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + FileName + ";Extended Properties=\"Excel 8.0;HDR=no;IMEX=0\""; string StrSQL = "SELECT * FROM [Sheet1$]"; System.Data.OleDb.OleDbDataAdapter DataAda = new System.Data.OleDb.OleDbDataAdapter(StrSQL, ConnectionString); DataSet DSTemp = new DataSet(); DataAda.Fill(DSTemp); DataAda.Dispose();
------解决方案--------------------
我推荐 npoi
------解决方案--------------------
这是我写的一个方法
/// <summary> /// 获取excel数据,返回一个dateset /// </summary> /// <param name="filePath">excel的物理路径</param> /// <param name="sheet">第几个sheet</param> /// <returns></returns> public static DataSet LoadDataFromExcel(string filePath, int sheet) { try { string strConn = ""; if (filePath.EndsWith("xls")) strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filePath + ";Extended Properties='Excel 8.0;HDR=False;IMEX=1'"; else if (filePath.EndsWith("xlsx")) strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + filePath + ";Extended Properties='Excel 8.0;HDR=False;IMEX=1'"; else return null; OleDbConnection OleConn = new OleDbConnection(strConn); OleConn.Open(); String sql = "SELECT * FROM [Sheet" + sheet + "$]";//可是更改Sheet名称,比如sheet2,等等 OleDbDataAdapter OleDaExcel = new OleDbDataAdapter(sql, OleConn); DataSet OleDsExcle = new DataSet(); OleDaExcel.Fill(OleDsExcle, "Sheet" + sheet); OleConn.Close(); return OleDsExcle; } catch (Exception err) { return null; } }
------解决方案--------------------
SpreadsheetGear/farPoint
------解决方案--------------------
在C#.net中定义和使用自己的特性
------解决方案--------------------
http://ufo-crackerx.blog.163.com/blog/static/11307877820119238517149/
http://www.e-iceblue.com/Download/download-office-for-net-now.html
------解决方案--------------------
http://ufo-crackerx.blog.163.com/blog/static/1130787782011112010495744/