I have an issue getting worksheet names from an Excel spreadsheet using OLEDB. The problem is that when I use GetOleDbSchemaTable, the resulting DataTable has more than jus
You can test EndsWith("$") instead of Contains("$") like below:
List lstsheetNames = new List();
String sheetName;
foreach (DataRow row in schemaTable.Rows)
{
sheetName = row.Field("TABLE_NAME");
String strTemp = sheetName.Split(' ');
if(strTemp.Length == 1 && sheetName.EndsWith("$"))
lstsheetNames.Add(sheetName.Substring(0, sheetName.Length - 1));
else if(strTemp.Length > 1 && strTemp.GetValue(strTemp.Length - 1).ToString().EndsWith("$'"))
lstsheetNames.Add(sheetName.Substring(1, sheetName.Length - 3));
}
I have used this code in a same problem and it works fine.
Edit : Sorry,I did not pay attention to this.I changed the code now.It might not the best or shortest way but it works.