try
{
OleDbConnection myConn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\學習資料\ACCPS2筆試機試\ACCPS2筆試\20070114筆試S2\答案.xls;Extended PropertIEs=Excel 8.0;");
myConn.Open();
OleDbDataAdapter thisAdapter = new OleDbDataAdapter("SELECT * FROM [Sheet1$]", myConn);
OleDbCommandBuilder thisBuilder = new OleDbCommandBuilder(thisAdapter);
DataSet thisDataSet = new DataSet();
thisAdapter.Fill(thisDataSet, "ExcelInfo");
this.dataGridVIEw1.DataSource=thisDataSet.Tables[0];
myConn.Close();
}
catch (OleDbException ex)
{
MessageBox.Show(ex.Message);
}