Hi itsjayshah;
I have checked. There is no problem with number.
The problem is when there is only number then the select query generates like SELECT * From ['9286$'A1:B4] which is not valid and the ' must be replaced.
Refer the below sample.
C#
private DataTable ImportExcel(String strFilePath)
{
DataSet ds = new DataSet();
//if (!File.Exists(strFilePath)) return false;
String strExcelConn = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + strFilePath + "; Extended Properties='Excel 8.0;HDR=Yes'";
OleDbConnection connExcel = new OleDbConnection(strExcelConn);
OleDbCommand cmdExcel = new OleDbCommand();
try
{
cmdExcel.Connection = connExcel;
//Check if the Sheet Exists
connExcel.Open();
DataTable dtExcelSchema;
//Get the Schema of the WorkBook
dtExcelSchema = connExcel.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
connExcel.Close();
//Read Data from Sheet1
connExcel.Open();
OleDbDataAdapter da = new OleDbDataAdapter();
string SheetName = dtExcelSchema.Rows[0]["TABLE_NAME"].ToString();
//cmdExcel.CommandText = "SELECT * From [" + SheetName + "]";
//Range Query
string query = "SELECT * From [" + SheetName + "A1:B4]";
query = query.Replace("'", "");
cmdExcel.CommandText = query;
da.SelectCommand = cmdExcel;
da.Fill(ds);
connExcel.Close();
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
finally
{
cmdExcel.Dispose();
connExcel.Dispose();
}
return ds.Tables[0];
}