像访问Sql一样访问Excel收藏
DataSet KDDataSet = new DataSet();
System.Data.OleDb.OleDbConnection objConn = new System.Data.OleDb.OleDbConnection("Provider=Microsoft.jet.OLEDB.4.0;Data Source=" + filename + ";Extended Properties=Excel 8.0");//这个更据不同的Excel版本不一样
//filename 为Excel的路径
objConn.Open();
//DataTable schemaTable = objConn.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, null);
// String tableName = schemaTable.Rows[0][2].ToString().Trim();
String SqlStr = "Select * from [Sheet1$]";
System.Data.OleDb.OleDbCommand command = new System.Data.OleDb.OleDbCommand(SqlStr, objConn);
System.Data.OleDb.OleDbDataAdapter DAP = new System.Data.OleDb.OleDbDataAdapter(command);
DAP.Fill(KDDataSet, "Sheet1");
//剩下的就是ADO的操作了,不用讲了吧