/// <Summary>
/// Extract the table data according to the path of the excel file
/// </Summary>
/// <Param name = "path"> excel file path </param>
Private void getdatafromexcelwithappointsheetname (string path)
{
// Connection string
String strconn = "provider = microsoft. jet. oledb.4.0;" + "data source =" + path + ";" + "extended properties = excel 8.0 ;";
Oledbconnection conn = new oledbconnection (strconn );
Conn. open ();
// Return the excel schema, including the name, type, Creation Time, and modification time of each sheet.
Datatable dtsheetname = conn. getoledbschematable (oledbschemaguid. tables, new object [] {null, "table "});
// String array containing the table name in excel
String [] strtablenames = new string [dtsheetname. rows. count];
For (int k = 0; k <dtsheetname. rows. count; k ++)
{
Strtablenames [k] = dtsheetname. rows [k] ["table_name"]. tostring ();
}
Oledbdataadapter mycommand = null;
Datatable dt = new datatable ();
// Query data from the specified table. All the table columns can be selected first.
String strexcel = "select * from [" + strtablenames [0] + "]";
Mycommand = new oledbdataadapter (strexcel, strconn );
Dt = new datatable ();
Mycommand. fill (dt );
Datagridview1.datasource = dt; // bind to the interface
}