<summary> Returns a list of workbooks contained in the specified file, or, if there is a worksheet, returns a ArrayList named after the workbook, otherwise null </summary> <param name= "strFilePath" > to get excel</param> <returns> If there is worksheet, return the ArrayList named after the workbook, otherwise return null </returns> Public ArrayList getexcelworksheets (string strFilePath) { ArrayList altables = new ArrayList (); OleDbConnection odn = new OleDbConnection (Getexcelconnection (strFilePath)); Odn. Open (); DataTable dt = new DataTable (); DT = Odn. GetOleDbSchemaTable (OleDbSchemaGuid.Tables, NULL); if (dt = null) { throw new Exception ("Cannot get the schema for the specified Excel. "); } foreach (DataRow dr in Dt. Rows) { String tempname = dr["table_name"]. ToString (); int idolarindex = Tempname.indexof (' $ '); if (Idolarindex > 0) { Tempname = tempname.substring (0, Idolarindex); } Fixed a bug in Excel2003 that a table with the names of Chinese characters is not recognized correctly. if (tempname[0] = = "") { if (tempname[tempname.length-1] = = "") { Tempname = tempname.substring (1, tempname.length-2); } Else { Tempname = tempname.substring (1, tempname.length-1); } } if (!altables.contains (tempname)) { Altables.add (Tempname); } } Odn. Close (); if (altables.count = 0) { return null; } return altables; } |