日期:2014-05-18 浏览次数:20554 次
OleDbConnection objConn = null; DataSet data = new DataSet(); try { string strConn = @"Provider=Microsoft.ACE.OleDb.12.0;Data Source=c:"待发工资.xlsx;Extended Properties='Excel 12.0;HDR=YES'";//IMEX=1为只读 //"Provider=Microsoft.Jet.OleDb.4.0;data source=c:"待发工资.xlsx;Extended Properties=""Excel 12.0;HDR=YES;IMEX=1"""; objConn = new OleDbConnection(strConn); objConn.Open(); //System .Data . DataTable schemaTable = objConn.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, null); //int SheetIndex = 0; //string tableName = schemaTable.Rows[SheetIndex][2].ToString().Trim(); string strSql = "Select * From [Sheet1$]"; OleDbCommand objCmd = new OleDbCommand(strSql, objConn); OleDbDataAdapter sqlada = new OleDbDataAdapter(); sqlada.SelectCommand = objCmd; sqlada.Fill(data); string str = ""; for (int i = 0; i < data.Tables[0].Rows[0].ItemArray.Length; i++) { str += data.Tables[0].Rows[0].ItemArray[i].ToString() + "."; } MessageBox.Show(str); objConn.Close(); } catch (Exception ex) { objConn.Close(); Console.WriteLine(ex.Message.ToString()); }