Error in Importing Excel File

Nov 15 2007 6:01 AM

Hi,

I have Exported some data in a Excel file using this code-

       Response.Clear();
        Response.AddHeader("content-disposition", "attachment;filename=dependencymatrix.xls");
        Response.Charset = "";
        Response.ContentType = "application/vnd.xls";
        System.IO.StringWriter stringWrite = new System.IO.StringWriter();
        System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
        resultGrid.AllowPaging = false;
        resultGrid.DataSource = dtResult;
        resultGrid.DataBind();
        resultGrid.RenderControl(htmlWrite);
        Response.Write(stringWrite.ToString());
        stringWrite.Dispose();
        htmlWrite.Dispose();
        Response.End();

Where "resultGrid" is a gridview.

Now I have to import this excel file.For this I have written the below code-

 String strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + strFilePath.ToString() + ";Extended Properties=Excel 8.0;";
 OleDbDataAdapter da1 = new OleDbDataAdapter("SELECT * FROM [dependencymatrix$]", strConn);
 da1.Fill(ds1);


Here i am getting this error-"The External table is not in correct format" .If I open the excel file and save as it as "Microsoft Excel workbook",then its working perfect.

Could any body help me to solve this problem?

My client dont want to do "save as" to the exported excel file.

Thanks in advance.