使用OleDb
-
- /// using System.Data.OleDb
- /// <summary>
- /// 返回Excel数据源
- /// </summary>
- /// <param name="filename">文件路径</param>
- /// <returns></returns>
- static public DataSet ExcelToDataSet(string filename)
- {
- DataSet ds;
- string strCon = "rovider=Microsoft.Jet.OLEDB.4.0;" +
- "Extended Properties=Excel 8.0;" +
- "data source=" + filename;
- OleDbConnection myConn = new OleDbConnection(strCon);
- string strCom = " SELECT * FROM [Sheet1$]";
- myConn.Open();
- OleDbDataAdapter myCommand = new OleDbDataAdapter(strCom, myConn);
- ds = new DataSet();
- myCommand.Fill(ds);
- myConn.Close();
- return ds;
- }
复制代码
-
目前出现的一个小问题是,没有搞懂如何接收dataset返回值,哎! |