Click here to Skip to main content
15,894,955 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I got this error while I tried to read an Excel file .
"External table is not in the expected format"

public static DataTable GetExcelData(string strFile)
{
  DataTable dttblExcelData = new DataTable();
  try
  {
    string strConn = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + strFile+ ";" + "Extended Properties='Excel 8.0;IMEX=1'";

    OleDbDataAdapter myCommand = new OleDbDataAdapter("SELECT * FROM [" + strFile+ "]", strConn);

    myCommand.Fill(dttblExcelData);
  }
  catch (Exception e)
  {
    string  errMsg = e.Message.ToString();
  }
  return dttblExcelData;
}
Posted
Updated 15-Nov-10 22:24pm
v3
Comments
Dalek Dave 16-Nov-10 4:24am    
Minor Edit for Grammar.
kapil0411 17-Nov-10 0:13am    
ya i check the extension of the file it isi9n correct format.
if i used "Extended Properties='HTML IMPORT;IMEX=1'";
then it work fine but when i am going to upload this file and export to data table
so space in column value get reduced.
i.g .:- if i have value like :- kapil r then it export in datattable as kapilr but actual data should be export (kapil r).
Thanks for giving you valuable time....

1 solution

I'm sure you can get the solution in 1st page of Google search. I found these which has answers

Excel "External table is not in the expected format."[^]

External table is not in the expected format.[^]
 
Share this answer
 
Comments
Dalek Dave 16-Nov-10 4:25am    
Yep, simple find!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900