By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,528 Members | 963 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,528 IT Pros & Developers. It's quick & easy.

error in importing excel file

P: 3

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

Expand|Select|Wrap|Line Numbers
  1. Response.Clear();
  2.         Response.AddHeader("content-disposition", "attachment;filename=dependencymatrix.xls");
  3.         Response.Charset = "";
  4.         Response.ContentType = "application/vnd.xls";
  5.         System.IO.StringWriter stringWrite = new System.IO.StringWriter();
  6.         System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
  7.         resultGrid.AllowPaging = false;
  8.         resultGrid.DataSource = dtResult;
  9.         resultGrid.DataBind();
  10.         resultGrid.RenderControl(htmlWrite);
  11.         Response.Write(stringWrite.ToString());
  12.         stringWrite.Dispose();
  13.         htmlWrite.Dispose();
  14.         Response.End();
Where "resultGrid" is a gridview.
Now I have to import this excel file.For this I have written the below code-

Expand|Select|Wrap|Line Numbers
  1. String strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + strFilePath.ToString() + ";Extended Properties=Excel 8.0;";
  2.  OleDbDataAdapter da1 = new OleDbDataAdapter("SELECT * FROM [dependencymatrix$]", strConn);
  3.  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
Nov 16 '07 #1
Share this Question
Share on Google+
1 Reply

Expert 2.5K+
P: 4,871
Here is another way to do it:
ASP.Net 2.0: Export GridView to Excel
Nov 16 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.