# Region get the sheet page (worksheet) name set in the Excel worksheet /// <summary> // get the sheet page (worksheet) in the Excel worksheet) name set // </Summary> /// <Param name = "excelfile"> Excel file name and path, eg: C: \ Users \ JK \ Desktop \ import test .xls </param> // <returns> Sheet Page name set </returns> private string [] getexcelsheetnames (string filename) {oledbconnection objconn = NULL; system. data. datatable dt = NULL; try {string connstring = string. empty; string filetype = filename. substring (Filename. lastindexof (". "); If (filetype = ". xls ") connstring =" provider = Microsoft. jet. oledb.4.0; "+" Data Source = "+ filename +"; extended properties = Excel 8.0; "; else //. XLSX connstring = "provider = Microsoft. ace. oledb.12.0; "+" Data Source = "+ filename +"; "+"; extended properties = \ "Excel 12.0; HDR = yes; IMEX = 1 \""; // create the connection object objconn = new oledbconnection (connstring); // open the database connection objconn. open ();// The data table dt = objconn containing the data architecture is obtained. getoledbschematable (oledbschemaguid. tables, null); If (Dt = NULL) {return NULL;} string [] excelsheets = new string [DT. rows. count]; int I = 0; // Add the worksheet name to the string array foreach (datarow row in DT. rows) {string strsheettablename = row ["table_name"]. tostring (); // invalid sheetname if (strsheettablename. contains ("$") & strsheettablename. replace ("'",""). endswith ("$") {excelsheets [I] = Strsheettablename. substring (0, strsheettablename. length-1);} I ++;} return excelsheets;} catch (exception ex) {MessageBox. show (ex. tostring (); return NULL;} finally {// clear if (objconn! = NULL) {objconn. Close (); objconn. Dispose ();} If (DT! = NULL) {DT. Dispose () ;}}# endregion