static void connectToXls() { string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=e:/tmp/123.Xls;Extended Properties=Excel 8.0;"; String strSql = "select * from [sheet1$]"; using (OleDbConnection Conn = new OleDbConnection(strConn)) { OleDbCommand command = new OleDbCommand(strSql); command.Connection = Conn; try { Conn.Open(); Console.WriteLine(Conn.ToString()); Object ob = command.ExecuteScalar(); Console.WriteLine(ob.GetType()); Console.WriteLine(ob); } catch (Exception e) { Console.WriteLine(e.Message); } Conn.Close(); } }
C#中访问Excel(xls)数据源的例程
最新推荐文章于 2021-08-04 21:16:57 发布