when i was reading the excel by using oledb, it is retrieving the data sucessfully. But when the sheet name contains '#' , it does not reading the data.
It gives the following error.
" is not a valid name. Make sure that it does not include invalid characters or punctuation and that it is not too long.
Loading
Khan Abrar AhmedPosted Jun 10, 2015, 7:15 AM
Karthi keyanPosted Jun 10, 2015, 7:38 AM
Khan Abrar AhmedPosted Jun 10, 2015, 7:23 AM
{
DataTable dt = null;
bool flag = false;
try
{
cn.Open();
// Get the data table containing the schema
dt = cn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
if (dt == null)
{
return null;
}
ArrayList arrayExcelSheets = new ArrayList();
// Add the sheet name to the string array.
foreach (DataRow row in dt.Rows)
{
flag = true;
string strSheetTableName = row["TABLE_NAME"].ToString();
//$$$ Updates: To remove the extra characters that appears in with SheetNames.
if (strSheetTableName.EndsWith("$"))
{
strSheetTableName = strSheetTableName.Substring(0, strSheetTableName.Length - 1);
}
else if (strSheetTableName.EndsWith("$'"))
{
strSheetTableName = strSheetTableName.Substring(1, strSheetTableName.Length - 3);
}
else
flag = false;
//$$$ Updates: To remove some extra sheets which are coming as Print_Area sheets
if (!strSheetTableName.Contains("Print_Area") && flag)
arrayExcelSheets.Add(strSheetTableName.Trim());
}
String[] excelSheets = arrayExcelSheets.ToArray(typeof(string)) as string[];
return excelSheets;
}
catch (Exception)
{
throw;
}
finally
{
// Clean up.
cn.Close();
}
}
Rajeesh MenothPosted Jun 10, 2015, 7:22 AM
OleDB converts the following characters:
. becomes #
! becomes _
` becomes _
[ becomes (
] becomes )
All the other characters are read correctly. Hope this helps someone.
Karthi keyanPosted Jun 10, 2015, 7:19 AM