private void btnCheck_Click(object sender, EventArgs e)
{
DataSet ds = new DataSet();
string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + txtPath.Text + ";" + "Extended Properties=Excel 8.0;";
OleDbConnection conn = new OleDbConnection(strConn);
conn.Open();
string strExcel = string.Empty;
OleDbDataAdapter myCommand = null;
int index = txtPath.Text.LastIndexOf("\\");
string filename = txtPath.Text.Substring(index + 1);
int index2 = filename.IndexOf(".");
string excelname = filename.Substring(0, index2);
strExcel = string.Format("select * from [{0}$]", excelname); //excelname为excel中工作薄
myCommand = new OleDbDataAdapter(strExcel, strConn);
myCommand.Fill(ds, excelname);
conn.Close();
}